Entity Framework 4.0 new support for T-SQL

Source: Internet
Author: User

EF4.0 new Executestorequery,executestorecommand,executefunction and other methods, the perfect support for T-SQL

The following code is an example of a nightmare of left join queries and report data queries in the EF before using LINQ:

LINQ left-Join query N-representation example code

1 public list<info> getmapunitlist (int MapId)


2 {


3 var var1 = from Mu in EPM. Mapunit


4 Join us in EPM. Unitstatus


5 on MU. Unit equals us. Unit into _unitstatus


6 Join CU in EPM. Contractunit


7 on MU. Unit equals CU. Unit into _contractunit


8 where MU. Map.mapid = = MapId


9 Select New Info ()


10 {


map = mu. Map


12,


mapstatus = null


14,


mapunit = mu


16,


Unit = mu. Unit


18,


status = _unitstatus.select (a => a.status). FirstOrDefault ()


20,


contract = _contractunit.select (a => a.contract). FirstOrDefault ()


22,


customer = null


24,


Boothtype = null


26};


var var2 = from v1 in var1


join MS in EPM. Mapstatus


on new {map = V1.map, status = V1.status}


equals new {map = Ms. Map, status = Ms. Status} into _mapstatus


Select New Info ()


32 {


map = null


34,


Mapstatus = _mapstatus.firstordefault ()


36,


Notoginseng mapunit = V1.mapunit


38,


= V1.unit


40,


status = V1.status


42,


contract = V1.contract


44,


customer = null


46,


Boothtype = null


48};


var var3 = from v2 in var2


from Ubtl in EPM. Unitboothtype


where UBTL. Unit.unitid = = V2.unit.UnitId


join CC in EPM. Customercontract


on V2.contract equals CC. Contract into _customercontract


Select New Info ()


55 {


map = null


57,


mapstatus = V2.mapstatus


59,


mapunit = V2.mapunit


61,


unit = V2.unit


63,


status = V2.status


65,


contract = V2.contract


67,


customer = _customercontract.select (a => a.customer). FirstOrDefault ()


69,


Boothtype = Ubtl. Boothtype


71};


list<info> infos = var3. ToList ();


return infos;


74}

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.