开发者

MVC3 - Adding a stored proc to the Model

开发者 https://www.devze.com 2023-03-08 06:27 出处:网络
I create the stored proc: CREATE PROCEDUREdbo.GetCampaigns @UserID varchar(15) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from

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 con开发者_运维技巧troller, 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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消