내가 두 개의 테이블이있는 데이터베이스가 있습니다건물 Linq는 일반적인 쿼리
public class A {
public string Name { get; set; }
public int Id { get; set; }
}
public class B {
public int Id { get; set; }
public bool Prop1 { get; set; }
public bool Prop2 { get; set; }
public bool Prop3 { get; set; }
public bool Prop4 { get; set; }
}
public class DataContext : DbContext {
DbSet<A> Table1 { get; set: }
DbSet<B> Table2 { get; set; }
}
내가 매개 변수 "Prop1"로 걸릴 것 기능을 쓰고 싶어를, "Prop2", ..., "PropX" 및 Table1에서 적절한 행을 리턴하십시오. 이 같은 뭔가 :
public List<A> GetByProp(string prop) {
var result = new List<A>();
using (var db = new DataContext()) {
result = db.Table1.Join(db.Table2, t1=>t1.Id, t2=>t2.Id, (t1,t2)=>new {t1,t2}).
Where(????????). //t=>t.t2.prop == true
Select(t=>t.t2);
}
return result;
}
이 할 수있는 적절한 방법은 무엇입니까?
... 나는 식 트리를 사용하려고했지만, 나는 그들의 stucked있어
어떻게 두 개의 점으로 표현을 구축
? (t.t2.prop == true)가어떻게
Join
의 일부로서 조건을 배치에 대한 일반적인var p = Expression.Parameter(typeof(???), t2); //??? - anonymous class var t = Expression.Constant(true, typeof(bool)); var e = Expression.Equal(p, t); var l = Expression.Lambda<Func<???, bool>>(e, p);
[This (http://stackoverflow.com/questions/307512/how-do-i-apply-orderby-on-an-iqueryable-using-a-string-column-name-within-a-gene)는'OrderBy'에 대한 것이지만 출발점이 될 수 있습니다. –
문자열로 속성 매개 변수가 필요합니까? 대신식이 될 수 있습니까? – Magnus
표현이 가능합니다. – Michael