我试图让我的用户构建自己的查询。我发现这个代码似乎解决了这个问题:
var predicate = PredicateBuilder.True<T1>();
if (a != "")
predicado = predicado.And(e1 => e1.field1.Contains(a));
if (b!= "")
predicado = predicado.And(e1 => e1.field2.Contains(b));
var TestQuery = db.T1.AsExpandable().Where(predicate).ToList();
这些是我的模型类:
public partial class T1
{
public long id_t1 { get; set; }
public string field1 { get; set; }
public string field2 { get; set; }
}
public partial class T1
{
public long id_t2 { get; set; }
public string field1 { get; set; }
public string field2 { get; set; }
}
但我需要一种方法在连接语句中使用PredicateBuilder
,如下所示:
var query = from f in db.T1
where (f.T1field1.Equals("something") && f.T1field2.Equals("something"))
join m in db.T2 on f.T1field1 equals m.T2field1
where (m.T2fiel1 != null && m.T2field2 != null )
select m;