locked
Left outer Join RRS feed

  • Question

  • How do you perform a left outer join through ado.net data services? 


    I have tried using a LINQ query such as:
    from et in db.EntityType
              join cetc in db.ClientEntityTypeConfiguration on et.Id equals cetc.EntityTypeId into temp
              from t in temp.DefaultIfEmpty<ClientEntityTypeConfiguration>()
              select t;


    I get an exception about converting a DataServiceOrderedQuery to a DataServiceQuery.

    Thanks.
    Saturday, September 20, 2008 2:37 PM

Answers

  • Hi Blue_Skies,

     

    Joins are not supported by the ADO.Net data services LINQ provider. It is possible to performt the joins on the enumerations obtained from the individual results through LINQ to objects though. However, that would imply a client side processing of the queries and therefore not recommended.

     

    For example you could do:

     

    var leftside = (from et in db.EntityType select et).AsEnumerable(); // => Results in all entities in EntityType to come to client

    var rightside = (from cetc in db.ClientEntityTypeConfiguration).AsEnumerable(); // => Results in all ClientEntityTypeConfiguration to come to client

    var result = from et in leftside

    join cetc in rightside on et.Id equals cetc.EntityTypeId into temp

    from t in temp.DefaultIfEmpty<ClientEntityTypeConfiguration>()

    select t;

     

    Also from MSDN:

     

    In LINQ you do not have to use join as often as you do in SQL because foreign keys in LINQ are represented in the object model as properties that hold a collection of items. For example, a Customer object contains a collection of Order objects. Rather than performing a join, you access the orders by using dot notation:

     

    You could potentially have ClientEntityTypeConfiguration as a property of EntityType through foreign key relationship to avoid the need for a join.

     

    Thanks

    Waseem

     

    Wednesday, October 15, 2008 8:46 PM
    Answerer