2

I have an Entity A which is related to entity B on a 1:M relationship. B is related to C in a 1:M relationship.

A --> B
B --> C

How do I go about including the collection of C when I include B on A?

I have this:

return (from d in _contextProvider.GetContext<SomeContext>().GetObjectQuery<A>().Include("B") select d).SingleOrDefault(); 

I tried this but throws error because it thinks C is related to A and can't find the relationship.

return (from d in _contextProvider.GetContext<SomeContext>().GetObjectQuery<A> ().Include("B").Include("C") select d).SingleOrDefault(); 

1 Answer 1

3

Try

  return (from d in _contextProvider.GetContext<SomeContext>().GetObjectQuery<A>().Include("B").Include("B.C") select d).SingleOrDefault();  
Sign up to request clarification or add additional context in comments.

1 Comment

You don't need to .Include("B") when you are calling .Include("B.C"), B will be included as well anyway.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.