MVC3 - 将存储过程添加到模型中
我创建存储过程:
CREATE PROCEDURE dbo.GetCampaigns
@UserID varchar(15)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT CampaignId, CampaignName, Expiry, LaunchDate FROM feeds.dbo.Campaigns WHERE userid=@UserID;
END
返回的campaignId 是一个唯一的键。
我将其拖放到 serverExplorer 中。我构建它并创建模型。我右键单击控制器来创建控制器、数据上下文等。它会弹出一个带有消息的框:
Unable to retrieve metadaat for xxx.Models.CampaignResult. One or more validation errors were detected during model generation: -System Data.Edm.EdmEntitytype: Entity Type getCampaingsResult has no key defined. Define a key for this entity type -System.Data.Edm.EdmEntitySet: EntityType: EntitySet GetCampaignResults is based on type GetCampaignResult that has no keys defined.
我很困惑。提前致谢。任何帮助表示赞赏。
I create the stored proc:
CREATE PROCEDURE dbo.GetCampaigns
@UserID varchar(15)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT CampaignId, CampaignName, Expiry, LaunchDate FROM feeds.dbo.Campaigns WHERE userid=@UserID;
END
The campaignId in the return is a unique key.
I drag and drop this into serverExplorer. I build it and it creates the Model. I right click on controller to create the controller, data context etc. It pops up a box with the message:
Unable to retrieve metadaat for xxx.Models.CampaignResult. One or more validation errors were detected during model generation: -System Data.Edm.EdmEntitytype: Entity Type getCampaingsResult has no key defined. Define a key for this entity type -System.Data.Edm.EdmEntitySet: EntityType: EntitySet GetCampaignResults is based on type GetCampaignResult that has no keys defined.
I'm confused. Thanks in advance. Any help appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 EF 执行存储过程有点奇怪 - 检查此链接:
http://beyondrelational.com/blogs/jalpesh/archive/2010/08/18/entity-framework-4-0-bind-stored-procedure-with-result-entity-class.aspx
It's a bit weird doing stored procs with EF - check this link:
http://beyondrelational.com/blogs/jalpesh/archive/2010/08/18/entity-framework-4-0-bind-stored-procedure-with-result-entity-class.aspx