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