c# - LINQ to SQL, multiple table join, generated SQL missing 2nd INNER JOIN -
can tell me why generated sql not contain 2nd inner join? seems have been replaced null check in clause? i'm not clear on why 2nd inner join not in generated sql.
c# code:
var cyclelist = o in entities.orders join c in entities.cycles on o.id equals c.orderid join calendar in entities.calendars on c.calendarid equals calendar.id o.unitid == unitid && o.companyid == companyid select c.id;
generated sql:
select [extent2].[id] [id] [dbo].[orders] [extent1] inner join [dbo].[cycles] [extent2] on [extent1].[id] = [extent2].[orderid] ([extent2].[calendarid] not null) , ( cast( [extent1].[unitid] int) = @p__linq__0) , ( cast( [extent1].[companyid] int) = @p__linq__1)
it looks query generator optimizing query.
since not selecting (or using in clause) fields calendars table in query, 1 join done between orders table , cycles table. it's faster check non-null foreign key join on table no fields used.
Comments
Post a Comment