There is a problem today, the code is like this.
public list<billname> querybill (Int[] id = null, string[] name = null) { list<billname> queryresult = new List<BillName> (); using (Var dbs = new dal.cashlogcontext ()) { var result = from a in dbs. billnames where (Querycondition (a), id, (Ele, arr) &NBSP;=>&NBSP;{&NBSp;return arr. Contains (ele.id); }) select a; } return queryresult; } public bool QueryCondition<T> (Billname ba , t[] conditionarray, func<billname, t[], bool> testequal) { if (conditionarray != null) return testequal (Ba, conditionarray); & NBsp; else return true; }
Then you will be prompted with error a lambda expression with a statement body cannot is converted to an expression tree
, just on the lambda expression. It's nothing wrong to think about it. And I checked it out and found this link.
The main idea is that if the database-related (IQueryable type) is to be prepared to be translated into SQL statements, you cannot use complex lambda conditions and can only use simple. Use complex lambda statements, only for IEnumerable types.
Solution:
1, Will (Ele, arr) = {return arr. Contains (ele.id); instead (Ele, arr) = arr. Contains (ele.id); You can do it.
2, or, use the asenumerable () function to force conversion to IEnumerable.
Simple and complex lambda expressions