MVC3 - 向模型添加存储过程

时间:2011-05-24 17:16:45

标签: linq-to-sql asp.net-mvc-3 model controller

我创建了存储过程:

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.

我很困惑。提前致谢。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)