1
내가 몇 엔티티 프레임 워크 7 (코어) 실체가 람다 표현식 사전을 기반으로 :은 다음과 같습니다 적용하고 ThenInclude
public class Person {
public virtual Address Address { get; set; }
public virtual ICollection<Hobby> Hobbies { get; set; }
}
public class Address {
public String Street { get; set; }
public virtual Country Country { get; set; }
}
을 다음과 같이 내가 문자열 배열이 있습니다
String[] entities = new String[] { "Hobbies", "Address.Country" }
이 문자열을 감안할 때 배열 내가 가지고 :
,369 : 내가 좋아하는 뭔가를 할 수 EF6에서context.Persons
.Include(x => x.Hobbies)
.Include(x => x.Address).ThenInclude(x => x.Country);
context.Persons.Include(entities[0]).Include(entities[1]);
그러나 EF7에서 포함은 문자열을 허용하지 않습니다.
private readonly Dictionary<String, LambdaExpression> _properties = new Dictionary<String, LambdaExpression>();
같은 것이다 : 나는 사전 생성
x => x.Hobbies is for "Hobbies"
x => x.Address.Country is for "Address.Country"
을 그리고 확장 있습니다
public static IQueryable<T> Include<T>(this IQueryable<T> source, Dictionary<String, LambdaExpression> properties) {
}
나는 사전은 다음을 적용 제공해야합니다
를포 R "X => x.Hobbies"단지 수행
source.Include(x => x.Address).ThenInclude(x => x.Country);
수있는이 : 표현식이 "X => x.Address.Country"추가 같은이
source.Include(x => x.Hobbies);
경우 끝내라?
를 포함해야 ThenInclude를 사용하여 ... 그건 내 문제 중 하나입니다 ... –
나는 아직 그것을 사용하지 않았기 때문에 다시 EF 7에 대한 확신이 없지만 어쩌면 이것이 당신을 도울 것입니다. –