Simple and complex lambda expressions

Source: Internet
Author: User

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;=&GT;&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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.