none
Querying related entities with inheritance

    Question

  • Given the following Entity Framework model with inheritance (where A and B are subtypes of Base, C has a 1-many association
    with A and D has a 1-many association with B):
        
        Base
        ^  ^
       /   \
    C - A   B - D

    What is the simplest and most efficient LINQ query to load all A's and B's with their corresponding C's and D's?
    Since I cannot write something like Bases.Include("A.C").Include("B.D"), I wonder what the best options are.
    Thursday, June 09, 2011 7:12 AM

Answers

  • Given the following Entity Framework model with inheritance (where A and B are subtypes of Base, C has a 1-many association
    with A and D has a 1-many association with B):
        
      Base
    
      ^ ^
    
      /  \
    
    C - A  B - D

    What is the simplest and most efficient LINQ query to load all A's and B's with their corresponding C's and D's?
    Since I cannot write something like Bases.Include("A.C").Include("B.D"), I wonder what the best options are.


    Hello,

    I suggest you can check the following page like yours need. http://stackoverflow.com/questions/3356541/entity-framework-linq-query-include-multiple-children-entities

    Thanks,

    Esters,


    Just a newbie for everything.
    Monday, June 13, 2011 8:20 AM

All replies

  • Given the following Entity Framework model with inheritance (where A and B are subtypes of Base, C has a 1-many association
    with A and D has a 1-many association with B):
        
      Base
    
      ^ ^
    
      /  \
    
    C - A  B - D

    What is the simplest and most efficient LINQ query to load all A's and B's with their corresponding C's and D's?
    Since I cannot write something like Bases.Include("A.C").Include("B.D"), I wonder what the best options are.


    Hello,

    I suggest you can check the following page like yours need. http://stackoverflow.com/questions/3356541/entity-framework-linq-query-include-multiple-children-entities

    Thanks,

    Esters,


    Just a newbie for everything.
    Monday, June 13, 2011 8:20 AM
  • I've posted the article "Improving Entity Framework Query Performance Using Graph-Based Querying" to www.codeplex.com

    This article presents a new way of expressing queries that span multiple tables in the form of declarative graph shapes. This approach, which is called Graph-based querying (or GBQ for short) can deal perfectly with the inheritance issue that is the topic of this thread. 

    Moreover, the article contains a thorough performance comparison of this new approach with EF queries. This analysis shows that GBQ quickly outperforms EF queries.

     

    Tuesday, August 30, 2011 6:55 AM