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}