In the ORM framework of the big line of the today, for the. NET industry people, want to learn EF, that LINQ learning is imperative AH. Today summarizes the common use of table connections.
Inner Join
Linq:
1 var list = ( from in customerdb.order2in Customerdb.orderitem on C.orderid equals O.orderitemid3 Selectnew {c = c. OrderId}). FirstOrDefault ();
The generated SQL
1 SELECT TOP(1) 2 [Extent1].[OrderId] as [OrderId]3 from [dbo].[Orders] as [Extent1]4 INNER JOIN [dbo].[OrderItems] as [Extent2] on [Extent1].[OrderId] = [Extent2].[Orderitemid]
Left Join
LINQ:
1 var list = (from c in Customerdb.order 2 join o in custome Rdb.orderitem on C.orderid equals o.orderitemid 3 into GRP 4 from grp in Grp.defaultifempty () 5 select
new {c = c.orderid, GRP = grp. Orderitemid}). FirstOrDefault ();
Generated sql:
1 SELECT TOP(1) 2 [Extent1].[OrderId] as [OrderId], 3 [Extent2].[Orderitemid] as [Orderitemid]4 from [dbo].[Orders] as [Extent1]5 Left OUTER JOIN [dbo].[OrderItems] as [Extent2] on [Extent1].[OrderId] = [Extent2].[Orderitemid]
Cross Join
Linq:
1 var list = ( from in customerdb.order2 3 Selectnew {c = c.orderid,o=o.orderitemid}). FirstOrDefault ();
Generated sql:
1 SELECT TOP (123[extent2].[ Orderitemid] as [Orderitemid]4from [dbo].[ Orders] as [Extent1]5 cross JOIN [dbo]. [OrderItems] As [Extent2]
Summary: The right connection is actually the order position of the two tables replaced,
The whole connection is to put the results of the left outer join together to go heavy on the line.
With Shun EF, you can speed up the development efficiency, look forward to the early arrival of the day, refueling Ah!!!
LINQ implements various connections to T-SQL