开发者

Entity Framework: Column must be mapped although it does have a default value?

I am trying to create an Entity Framework 4 model based on a legacy SQL server 2008 database. Since the model is going to be published in a web service, I need t开发者_Go百科o omit an integer column called NewsletterSubscribed from one of the model's entities.

After removing the column in the EF designer I got the following compilation error:

Error   59  Error 3023: Problem in mapping fragments starting at line 356:Column Users.NewsletterSubscribed in table Users must be mapped: It has no default value and is not nullable.
    C:\Users\Adrian\Documents\Sites\Zeiterfassung\Zeiterfassung\API\V1\EFModel.edmx 357 15  Zeiterfassung

But the column seems to have a default value of 0 bound to it. I tried running this SQL statement against the database:

ALTER TABLE [dbo].[Users] ADD  DEFAULT ((0)) FOR [NewsletterSubscribed]

But that also fails:

Msg 1781, Level 16, State 1, Line 3 Column already has a DEFAULT bound to it. Msg 1750, Level 16, State 0, Line 3 Could not create constraint. See previous errors.

So either the column does not have a default value (in which case I am not sure why I can't create one), or Entity Framework doesn't see it. What is going on?

Thanks,

Adrian


Open the .edmx with Visual Studio XML editor rather than with the Entity Designer, and add a DefaultValue="0" attribute to the unmapped column in the SSDL. For some reasons these are not generated from the database.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜