Entity Framework 4.2 \"The type is not attributed with EdmEntityTypeAttribute but is contained in an assembly attributed with EdmSchemaAttribute

不羁岁月 提交于 2019-12-03 13:01:40

Figured it out.

When I first started the program I was using an ObjectContext with the .edmx.

Then I read about EF 4.2 and decided to use DbContext.

The problem was my .edmx file was generating classes, as well as the DbContext T-4s.

The solution was to turn off code generation in the .edmx.

So now, only the DbContext T-4s are generating my POCO classes.

Hope this questions helps someone else in the future!

I had a similar problem - it seems that in some cases (for example, when using WCF Data Services 5.2.0), it's a problem to have code-first/DbContext classes in the same assembly as EDMX/model-first/generated classes. For me, moving the DbContext classes into a separate assembly fixed the problem.

Note that I didn't have a problem with code-first + model-first in the same assembly when just accessing the DB. But as soon as I added another layer (WCF Data Services) I ran into the EdmSchemaAttribute error.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!