내가이이 저장소 코드를 기반으로 다음과 같은 확장 방법DbSet는
/// <summary>
/// Provides a statically typed interface for db includes
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="set">The set.</param>
/// <param name="includes">The includes.</param>
/// <returns>DbSet<T>.</returns>
public static DbSet<T> Include<T>(this DbSet<T> set, params Expression<Func<T, object>>[] includes) where T : class
{
if (includes != null)
{
foreach (var expression in includes)
{
set.Include(expression);
}
}
return set;
}
여기
그러나https://github.com/carbonrobot/FullStackEF/tree/master/src
발견을 추가 한 루프 확장 방법을 포함 나는 이것을 활용하는 경우 다음
public ServiceResponse<Town> Get(int id)
{
Func<Patient> func = delegate
{
using (var context = _contextFactory())
{
return context.Get<Town>(id, x => x.County);
}
};
return this.Execute(func);
}
마을 클래스에는 카운티 en tity.
베이스가 아닌 확장 메서드를 호출 할 때 무한 루프가 발생합니까?
내가 여기서 잘못하고있는 아이디어가 있습니까?
감사 : 그와
여기에 올바른 사용자 정의 메소드 서명 및 구현이 말했다된다. Repo가 DbSet을 사용하여 메서드를 체인으로 반환 할 때 한 가지 질문이 있습니다. .include (includes) .find (id) 확장 메서드가 return IQueryable이기 때문에 (DbSet 과 연계 할 수있는 능력이 없어졌다. 어떤 아이디어라도? –
흠, 해결할 수없는 것처럼 들리지만'Include'는 ' 어쨌든'Find '로 작업하기 때문에'Find'로 체인으로 연결하는 것은 의미가 없다고 생각합니다. 정규 LINQ 체인이 작동해야합니다.'Include'의 결과는'DbSet'이 아닙니다. –
Ok 좋아, 기본적으로 .include (includes) .select (x => x.Id == id); (find 예제와 관련하여) 쿼리 할 수있는 결과를 필터링하려면? –