I have one edmx in one dll, and need to have an entity in an edmx in another dll inherit from an entity in the first edmx. I have attempted to extend the initial context of the first edmx with the second with no success. What is the best way to accomplish this?
-
This might help: http://stackoverflow.com/questions/5558309/entity-framework-inserting-entity-with-multiple-models-and-databases/5598664#5598664 – Danny Varod May 07 '11 at 00:38
-
I was able to accomplish this using EF Code First and this: http://stackoverflow.com/questions/6300990/ef-ctp5-context-inheritance-across-multiple-assemblies – kroehre Oct 09 '11 at 00:06
-
The problem with this site is that you may never know. Suggestions on meta to correct this were all voted down. – Danny Varod Oct 10 '11 at 15:12
2 Answers
That is not possible. One EDMX = one ObjectContext
and no inheritance among them. I found a special hack how to force context to load multiple EDMXs but they must be in the same assembly and it works only for cross EDMX linq-to-entities queries.
I think you must model whole inheritance hierarchy again in the second EDMX and reuse same POCO class for the parent = parent entity must be in both EDMXs. Check these articles about working with multiple models (part 1, part 2). There is possibility to reusing CSDL types from one EDMX in other EDMX for defining associations but it will not work for inheritance because inheritance is defined in MSL which cannot be reused.

- 1
- 1

- 360,892
- 59
- 660
- 670
-
I ended up rethinking my logic so this isn't a requirement anymore. I wish this was possible, hopefully Entity Framework will be capable of doing something similar in the future. – kroehre May 06 '11 at 21:36
Inheritance may not be the best solution for this. I would suggest dependency injection from both entities from separate assemblies, e.g.:
public class CompositeObj
{
protected ObjectType1 obj1 { get; set; }
protected ObjectType2 obj2 { get; set; }
public CompositeObj(ObjectType1 obj1, ObjectType2 obj2)
{
this.obj1 = obj1;
this.obj2 = obj2;
}
public string Property1 { get { return this.obj1.Property1; } }
public string Property2 { get { return this.obj2.Property2; } }
pulbic string Property3 { get { return this.obj1.Property1 + this.obj2.Property2; } }
}

- 11,025
- 8
- 46
- 70