2013-04-24 3 views
0

이 포함 문을 줄이는 방법은 무엇입니까?EF에서 엄청난 양을 줄입니다.

var query = Context.Businesses 
.Include(b => b.Categories) 
.Include(b => b.Branches.Select(br => br.Address)) 
.Include(b => b.Branches.Select(br => br.BranchType)) 
.Include(b => b.Branches.Select(br => br.CustomFields)) 
.Include(b => b.Branches.Select(br => br.Phones)) 
.Include(b => b.Branches.Select(br => br.OpeningTimes.Select(ot => ot.WorkingPeriods))); 

나는 SPROC를 사용하는 것에 대해 생각했지만 어떻게 반환되었는지 알 수 없다.

이렇게 짧게하는 하드 코드되지 않은 방법이 있습니까? 아마도 Branch의 모든 속성을 처리하는 외부 람다일까요?

답변

1

this question의 대답과 비슷한 것을 할 수 있습니다. 생성 된 SQL이 될 필요가 없습니다 있도록이 기능을 컴파일 할 수있는 방법이 있나요

Business business = context.BusinessesComplete().Where(b => ...etc); 
+0

: 다음

public static class DataContextExtensions { public static IQueryable<Business> BusinessesComplete(this DataContext context){ return context.Businesses .Include(b => b.Categories) .Include(b => b.Branches.Select(br => br.Address)) .Include(b => b.Branches.Select(br => br.BranchType)) .Include(b => b.Branches.Select(br => br.CustomFields)) .Include(b => b.Branches.Select(br => br.Phones)) .Include(b => b.Branches.Select(br => br.OpeningTimes.Select(ot => ot.WorkingPeriods))); } } 

과 같이 사용 : 그래서 귀하의 경우,이 같은 확장 메서드를 만들 다시 계산할 때마다? – Shimmy

+0

EF 5에서는 LINQ 쿼리에 사용할 수 있으며 기본적으로 사용하도록 설정되어 있지만 이전 버전에서는 사용할 수 있는지 확실하지 않습니다. 읽는 가치가있다 : http://msdn.microsoft.com/en-us/data/hh949853.aspx – greg84

관련 문제