Dictionary operation
C #
VaR vhe =NewDictionary <string, string> ();
VaR querystring = context. Request. querystring;
Foreach(StringItemInQuerystring ){
Vhe. Add (item, commonfunc. convertobjecttostring (querystring [item]);
}
ReturnVhe;
For the above C # CodeUse LINQ to object for coding
Linqtoobject
1:
VaR query = from itemInQuerystring. oftype <string> () SelectNewKeyvaluepair <String,String> (Item, querystring [item]); var vhe =NewDictionary <string, string> ();Foreach(VAR itemInQuery) {vhe. Add (item. Key. tostring (), item. value. tostring ());}
ReturnVhe;
2:
ReturnQuerystring. oftype <string> (). todictionary (item => item, item => querystring [item]);
Left Outer Join Operation
SQL:
Code
Select [ T0 ] . [ Memberid ] , [ T0 ] . [ Membername ]
From [ DBO ] . [ Memberinfo ] As [ T0 ]
Left Outer Join [ DBO ] . [ Membersort ] As [ T1 ] On ( [ T1 ] . [ Membertype ] = 0 ) And
( [ T0 ] . [ Memberid ] = [ T1 ] . [ Memberid ] )
Order By ( Case When [ T1 ] . [ Sortnumber ] Is Not Null Then [ T1 ] . [ Sortnumber ]
Else 9999
End )
LINQ:
Code
VaR data = From m In DB. memberinfo
Join s In DB. membersort on M. memberid equals S. memberid
Into X
From CX In X. Where (d => D. membertype = 0 ). Defaultifempty ()
Orderby Cx. sortnumber. hasvalue ? Cx. sortnumber. value: 9999
Select m;
Group orderby sum operation
SQL:
Code
Select [ Sid ] , CID, Sum (Visitcount ), Sum (Resultcount ), Sum (Validcount)
From DBO. countvisit
Where Reportdate Between ' 2010-03-04 ' And ' 2010-03-08 ' And
[ Sid ] Like ' % M % '
Group By [ Sid ] , CID
Order By [ Sid ] , CID
LINQ:
Code
VaR list = New List < Countvisitentity > ();
Using (VAR TB = Getcountvisitbyparam (svcp, Ref Flippageoption )){
If (Tb. Rows. Count > 0 ){
VaR Query = From item In TB. asenumerable ()
Group item New {Sid = Item. Field < String > ( " Sid " ),
CID = Item. Field < String > ( " CID " )
} Into result
Orderby result. Key. Sid, result. Key. CID
Select New Countvisitentity (){
Sid = Result. Key. Sid,
CID = Result. Key. CID,
Xx = Result. sum (o => O. Field < Int32 > ( " Xx " )),
Xxx = Result. sum (o => O. Field < Int32 > ( " Xxx " )),
Xxxx = Result. sum (o => O. Field < Int32 > ( " Xxxx " ))
};
List = Query. tolist ();
}
}
Return List;