First and multiple builds

I have a subclass in another assembly for its base class. Parent is the POCO class used for the first EF code.

When I try to add an inherited class instance in the database, I get the InvalidOperationException The: . Cannot find object mapping for type with identifier "Foo.Bar.MyInheritedClass".

It works fine if the subclass is in the same assembly as the base class.

In regular EF, the solution is a call to ObjectContext.MetadataWorkspace.LoadFromAssembly (assembly) . But I can not understand how this relates to Code First.

Any tips?

I am using Entity Framework 4.1 RC.

+5
source share
3 answers

I solved this by inheriting from the first DbContext compiler, adding DbSet <> for the derived class, and then adding new instances of the derived type to it.

The posted code on the MSDN forum is here.

+3
source

I know this post is a bit outdated, but I was able to accomplish this using the @Dave recommendation inside the constructor:

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

EF (Entity Framework 4), , .

, , EF , . , foo, .

+1

All Articles