none
LoadOptions Join type RRS feed

  • Question

  • Simple Question:

     

    How can I control what type of join (inner or left/right outer) is generated when I use LoadOptions.LoadWith. In my case only inner joins are generated.

     

    Ben

    Wednesday, November 12, 2008 1:56 PM

Answers

  • L2S will generate an inner join if it thinks the relationship is strictly (1:1) based on the FK being declared as not null.  Otherwise it will generate a left outer join.
    Thursday, November 13, 2008 4:13 PM
    Moderator

All replies

  • I don't think the type of join is applicable when using LoadOptions. LINQ to SQL does not always do a single SQL query to get the results, so it will load entries where no child records exist.

     

    For example:

     

    In Northwind if you wanted a set of Orders with matching child Order_Details items, you'd automatically have any Order which has no Order_Details anyway. e.g. var query = from o in db.Orders where o.ShipVia=='Test' select o;

     

    Similarly, Order.CustomerID is nullable, but if you set the load option to get all parent Customer entries it would still load Orders where .CustomerID IS NULL.

     

    Perhaps you can elaborate on how you need to use it.

     

    Howard

     

    Thursday, November 13, 2008 10:30 AM
    Answerer
  • L2S will generate an inner join if it thinks the relationship is strictly (1:1) based on the FK being declared as not null.  Otherwise it will generate a left outer join.
    Thursday, November 13, 2008 4:13 PM
    Moderator