I는 다음과 같습니다 쿼리가 있습니다SQL 쿼리에 LINQ를 최적화
foreach (var o in FetchLatestOrders(0, 10))
{
Console.WriteLine("{0} {1}", o.Code, o.Customer.Name);
}
이것은 생산 : 나는 순서의 정보와이 정보를 생성 한 사용자를 인쇄해야
public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)
{
DatabaseDataContext db = new DatabaseDataContext();
return (from o in db.Orders
orderby o.CreatedDate descending
select o)
.Skip(pageIndex * recordCount)
.Take(recordCount)
.ToList();
}
을 주문을 가져 오는 SQL 쿼리와 각 주문에 대해 하나의 쿼리를 사용하여 고객을 불러옵니다. 주문을 가져오고 고객을 하나의 SQL 쿼리로 가져올 수 있도록 쿼리를 최적화 할 수 있습니까?
감사
UDPATE
는 : sirrocco의 제안으로이 같은 쿼리를 변경하고 그것을 작동합니다. 하나의 선택 검색어 만 생성됩니다.public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)
{
var options = new DataLoadOptions();
options.LoadWith<Post>(o => o.Customer);
using (var db = new DatabaseDataContext())
{
db.LoadOptions = options;
return (from o in db.Orders
orderby o.CreatedDate descending
select o)
.Skip(pageIndex * recordCount)
.Take(recordCount)
.ToList();
}
}
감사합니다. sirrocco.
와우, 정말 좋았어. 나는 이것을 구현하고 질의 시간을 25 초에서 1.5 초로 줄였습니다. 훌륭한 정보 덕분입니다. – BastanteCaro
http://stackoverflow.com/questions/11262785/optimizing-repositorys-submitchanges-method에 응답 해 주시겠습니까? – Lijo