Cannot construct entity or complex type _ back-end in LINQ to Entities query

Source: Internet
Author: User
Yes, to make sure that EF knows your query type, personal experience, the EF query only supports the mapping entity objects generated by the table structure, and simple C # types, to return directly to the newly defined type of the individual, to be converted with an anonymous type
C # code?                               1 2 3 4 5 from T in db.projects select new { T=t,}

After the tolist is really calculated and then converted to another type

--------------------------------------------------------------------

Error code: var  orders = db. Orders.where (O => o.userid == userid). Select (c =>                    new  Order                    {                          Orderid = c.orderid,                        OrderDate  = c.orderdate,                        Total = c.total,                        orderdetails =  Db. Orderdetailss.Where (Od => od. Orderid == c.orderid). ToList ()                      }                      ). ToList ();             Correct code: var  orders = db. Orders.where (O=>o.userid==userid). ToList (). select                  (c  =>                 new  Order                  {                    orderid =  c.orderid,                     orderdate = c.orderdate,                      total = c.total,                      OrderDetails  = db. Orderdetailss.where (Od => od. Orderid == c.orderid). ToList ()               }                ). ToList ();       principle: linq  When selecting data   can not new  known objects, only anonymous.   But if you can new  a known class from a  List  list  .   http://www.cnblogs.com/studylife/p/3202616.html

---------------------------------------------------------------


Called after the new complex type. Asnotracking () on the premise that you do not need to delete the object of change.

----------------------------------------------

The EF is not able to directly new out its own entity classes.

First query the anonymous class, and then new
var aaa = query. ToList (). Select (data => new Tb_item {num_iid = data. A.key, num = data. A.sumnum, title = data. B.firstordefault (U => u.num_iid = = data. A.key). Title}). ToList ();

Look, I've got this code a little more than yours. ToList ().
LINQ to Entities

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.