我正在尝试构建搜索功能,我正在寻找构建表达式树。
很抱歉坦率地说我不确定采取哪种方法..
我有三个表要搜索并基于3个搜索字段。
表1:
表2:
表3:
搜索字段我是:
OutPut列表:
TCode,Band,T1Id。
Class Response{
public string TCode {get;set}
public string RTCode {get;set}
public int Band {get;set}
}
我试图获得IQuerable<Table1>
并开始构建搜索条件,如
queryObj = IQuerable<Table1>
If(TCode not empty)
{
queryObj = queryObj.Where(x=>x.TCode== input.TCode));
}
If(Band not Empty)
{
queryObj = queryObj.Include(x=>x.table2.Where(x=>x.Brand==input.Brand))
}
if(rTcode Not empty)
{
queryObj = queryObj.Include(x=>x.table3.Where(x=>x.RTCode==input.RTCode)
}
然后我想选择TCode,Band,T1Id Column。
var queryObj.SelectMany(x=>x.table2).Select(y=> new Response(){
T1Id = y.T1Id,
Band= y.Band,
TCode = y.Table1.TCode
}).ToList()
我收到转换为ToList时的属性表达式无效错误。
属性表达式&#39; x =&gt; {来自表2中的 [_1]。表2其中([y] .Band == __inputObj_Band_0)选择 [Y]}&#39;无效。表达式应代表属性 访问:&#39; t =&gt; t.MyProperty&#39;
我确信上述陈述不正确。
所以任何人都可以告诉我如何在功能上进行此搜索,以便可以在不同字段的任何位置进行扩展或添加更多表格。