Now we will write LINQ Queries in VB.Net for INNER JOIN, LEFT JOIN and RIGHT JOIN.
Using db As New MyTestEntities 'Inner Join ' Dim results = (From cust As Customer In db.Customers _ Join ct As City In db.Cities _ On ct.Id Equals cust.City_Id _ Select cust.Name).ToList() 'Left Join ' results = (From cust As Customer In db.Customers _ Group Join ct As City In db.Cities _ On ct.Id Equals cust.City_Id Into Joined = Group _ From lj In Joined.DefaultIfEmpty() _ Select cust.Name).ToList() 'Right Join (Just swap it) ' results = (From ct As City In db.Cities _ Group Join cust As Customer In db.Customers _ On ct.Id Equals cust.City_Id Into Joined = Group _ From rj In Joined.DefaultIfEmpty() _ Select ct.Name).ToList() End Using
No comments:
Post a Comment