2

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?

3

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.
0

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; } }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.