Entity Framework Code First and Multiple Assemblies

天大地大妈咪最大 提交于 2019-11-30 15:19:50

I solved this by inheriting from the first assembliy's DbContext, adding a DbSet<> for the derived class, and then adding new instances of derived type to to that.

Posted code on MSDN forum here.

kroehre

I know this post is a bit old, but I was able to accomplish this using @Dave's recomendation inside the constructor:

public Context() {
    ((IObjectContextAdapter)this).ObjectContext.MetadataWorkspace.LoadFromAssembly(
        System.Reflection.Assembly.GetAssembly(
             typeof(--[Inherited DbContext]--)));
}
John

I'm quite new to EF (Entity Framework 4) and I got the same exception when I made changes in the model.

My problem turned out to be that I did not know EF need all the names on all the navigation properties to agree, not only their type. For example if there is a navigation property named foo, then there needs to be a declared variable in the corresponding class with the very same name.

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