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: stackoverflow.com/questions/5558309/…Danny Varod– Danny Varod2011-05-07 00:38:40 +00:00Commented May 7, 2011 at 0:38
-
I was able to accomplish this using EF Code First and this: stackoverflow.com/questions/6300990/…kroehre– kroehre2011-10-09 00:06:56 +00:00Commented Oct 9, 2011 at 0:06
-
The problem with this site is that you may never know. Suggestions on meta to correct this were all voted down.Danny Varod– Danny Varod2011-10-10 15:12:15 +00:00Commented Oct 10, 2011 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 Comment
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; } }
}