2016-10-03 3 views
0

내가 내가 포함의 배열에 전달하고 엔티티 프레임 워크로드를 갖고 싶어 방법과 표현의 배열에 전달 된 협회 다음 한 포함 이 코드를 실행 한 것과 같은 방식으로 연결이로드되지 않습니다.일반 코드

context.Entities.Include(a => a.association).Find(id) 

내 코드가 작동하지 않는 이유는 알 수 없습니다.

답변

2

Include 방법의 결과를 무시하기 때문에. 아래 방법과 일치하도록 메소드를 수정해야합니다.

public static async Task<T> FindAsync<T>(this GSCMContext context, 
     Expression<Func<T, bool>> match, 
     params Expression<Func<T, object>>[] includes) 
     where T : BaseEntity 
{ 
    IQuerable<T> query = context.Set<T>(); 

    if(includes != null) 
    { 
     foreach (var include in includes) 
     { 
      // Include returns result 
      query = query.Include(include); 
     } 
    } 
    return await query.SingleOrDefaultAsync(match); 
} 
관련 문제