why Linq designers can't make things simple (more sql like)
. ( sql) OO. Linq ( #) - OO. . # intellisense .
, , LEFT JOIN ( , LEFT OUTER JOIN), , - , ).
, , GROUP JOIN, .
List<int> myInts = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
List<int> myOtherInts = new List<int>() { 1, 3, 5, 7, 9, 11, 13 };
var query = from i in myInts
join j in myOtherInts on i equals j into g
select new {key = i, myGroup = g};
foreach (var grouping in query)
{
Console.WriteLine("--{0}", grouping.key);
foreach (var x in grouping.myGroup)
Console.WriteLine(x);
}
, DefaultIfEmpty, - - / - . DefaultIfEmpty .
, :
var query = myInts.GroupJoin(
myOtherInts,
i => i,
j => j,
(i, g) => new { key = i, myGroup = g }
);
, ?
. . 50 1000 , 50 .
from c in dc.Customers
join o in dc.Orders on c.custid equals o.custid into someOrders
select new CustomerWithOrders()
{theCustomer = c, theOrders = someOrders};
CustomerOrder. 5 , 5 , , . 0 , . 50 1000 , 50-1049 , .
from c in dc.Customers
join o in dc.Orders on c.custid equals o.custid into temp
from x in temp.DefaultIfEmpty()
select new CustomerOrderHybrid() {theCustomer = c, theOrder = x}
LEFT JOIN, . GROUP JOIN, , LEFT JOIN . .