I am Use GroupJoin in Linq by EF but generate inner join RRS feed

  • Question

  • Hi

    I write this Linq Query to generate left outer join :

                    .Where(bimeName => bimeName.Id == 8944731)
                        , bn => new { BID = bn.Id, ELHNO = bn.ElhNo }, elhaghie => new { BID = elhaghie.BId, ELHNO = elhaghie.ElhNo }
                        , (bn, elhaghie) => new
                            Elhaghie = elhaghie.DefaultIfEmpty()
                    .Select(bimeName => new { Id = bimeName.Id, ElhNo = bimeName.ElhNo, BeginDate = bimeName.BeginDate, Elhaghie = bimeName.Elhaghie });

    but, result of this query has been inner join. I investigate this problem by detail, so see that because i have Asociation for two entities CarSalesBN,CarSalesElh. EF generate inner join. 

    class CarSalesBN


    CarSalesElh CarSalesElhRef


    when i inverse relation, my problem been solved and EF genarte left outer join.

    my question is that, why EF Use Association to generate SQL Query, I am not used navigation properties in Linq Query and not see any related document in MSDN for that.

    • Moved by CoolDadTx Monday, December 21, 2015 4:17 PM EF related
    Monday, December 21, 2015 12:19 PM


  • Sorry, I don't follow your question.

    It's inferring how the relationship is supposed to work.

    What I'm saying is if you want to specify something as being 0:m you should explicitly use HasOptional with code first.

    Did you follow the link and read the article?

    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    • Proposed as answer by Fred Bao Monday, December 28, 2015 7:37 AM
    • Marked as answer by Fred Bao Wednesday, January 6, 2016 9:31 AM
    Monday, December 21, 2015 9:05 PM

All replies