LinqConnect Documentation
In This Topic
    Querying Across Relationships
    In This Topic
    Querying Across Relationships
    LinqConnect Documentation
    Querying Across Relationships
    [email protected]

    In this article we use a model created with the help of Entity Developer (read more about it in the section Using Entity Developer) or created manually (read more about it in the section Creating LinqConnect Classes Manually).

    Now you can use relationships when you write queries simply by referring to the relationship properties defined in your class.

    CautionNote:

    To run samples from this article include the following namespace before your code:

    using CrmDemoContext;
    
    
    Imports CrmDemoContext
    
    

    Use the following examples for quering accross relationships:

    CrmDemoDataContext db = new CrmDemoDataContext();
    
    var BostonCompOrders =
         from c in db.Companies
         from o in c.Orders
         where c.City == "Boston"
         select new { c, o };
    Dim db As New CrmDemoDataContext
    
    Dim BostonCompOrders = 
         From comp In db.Companies, ord In comp.Orders _
         Where comp.City = "Boston" _
         Select Company = comp, Order = ord
    

    The above query uses the Orders property to form the cross product between companies and orders, producing a new sequence of Company and Order pairs.

    It's also possible to do the reverse.

    CrmDemoDataContext db = new CrmDemoDataContext();
    
    var BostonCompOrders =
         from o in db.Orders
         where o.Company.City == "Boston"
         select new { c = o.company, o };
    Dim db As New CrmDemoDataContext
    
    Dim BostonCompOrders = 
         From ord In db.Orders _
         Where ord.Company.City = "Boston" _
         Select Company = ord.Company, Order = ord
    

    In this example, the orders are queried and the company relationship is used to access information on the associated company object.

    This topic is continued in: Modifying and Saving Entities. You can read more about LINQ queries in the LINQ Query Samples article.