Is one of these VB.NET LINQ to SQL Left Join options superior to other?
I'm not sure which to use.
Method 1: Lambda
Dim query = From A In DB.Product_Categories
From B In DB.MasItems.Where(Function(x) CBool(x.itemkey = A.ItemKey)).DefaultIfEmpty
Select A.Name
Method 2: Group Join
Dim query = From A In DB.Product_Categories
Group Joi开发者_开发百科n B In DB.MasItems On B.itemkey Equals A.ItemKey Into X = Group
From Y In X.DefaultIfEmpty
Select A.Name()
The generated SQL is the same for both queries, so in LINQ to SQL it is really personal preference.
EDIT: This is true for LINQ to Objects.
I don't know about LINQ to SQL.
Method 2 is faster, since GroupJoin
builds a hashtable internally.
Method 1 is O(n2)
, since it needs to search all of MasItems
for each category.
精彩评论