내가 다루는 한 가지 차이점은 그룹화의 차이입니다.
개체에 linq을 그룹화하면 계층 적 모양의 결과 (키, 자식 개체 포함)가 나타납니다.
SQL에서 그룹화 할 때 키와 집계 만 가져옵니다.
linq에서 sql으로 그룹화 할 때 자식 개체 (집계 이상)를 요청하면 linq to sql은 해당 자식 개체를 가져 오기 위해 키를 사용하여 각 그룹을 다시 쿼리합니다. 그룹 수천 명이 있다면 수천 왕복 수 있습니다.
//this is ok
var results = db.Orders
.GroupBy(o => o.CustomerID)
.Select(g => new
{
CustomerId = g.Key,
OrderCount = g.Count()
});
//this could be a lot of round trips.
var results = db.Orders
.GroupBy(o => o.CustomerID)
.Select(g => new
{
CustomerId = g.Key,
OrderIds = g.Select(o => o.OrderId)
});
// this is ok
// used ToList to separate linqtosql work from linqtoObject work
var results = db.Orders
.Select(o => new {o.CustomerId, o.OrderId})
.ToList()
.GroupBy(o => o.CustomerId)
.Select(g => new
{
CustomerId = g.Key,
OrderIds = g.Select(o => o.OrderId)
});
도 http://stackoverflow.com/questions/2388022/case-insensitive-string-compare-with-linq-to-sql-and-linq-to-objects –