In a word, convert a LINQ statement to an SQL statement

Source: Internet
Author: User



Public ienumerable<vmb_report> reportview_list (vmb_reportconditions Requiredmodel)
{

ienumerable<vmb_report> Resultmodel = new list<vmb_report> ();
iqueryable<merchant> merchantlist;
Merchantlist = Report_list ();

#region Get Vmb_report collection from Merchantlist


Resultmodel = Merchantlist.select (o = new Vmb_report
{

Merchantid = O.merchantid,
MID = O.mid,
DBA = O.dba,
Dbaphone = O.dbaphone,
ContactName = O.contactname,
TOTALSALESYTD = O.MERCHANTVOLUME.TOTALSALESYTD,
BANKCARDAVGTICKETYTD = O.MERCHANTVOLUME.BANKCARDAVGTICKETYTD,
Ytdprofit = O.merchantvolume.ytdprofit,
Entereddate = O.merchantstatus.entereddate,
Installeddate = O.merchantstatus.installeddate,
Status = O.merchantstatus.status,
Regionname = O.merchantreps.where (A = A.levelnumber = = 1). FirstOrDefault (). Rep.Region.RegionName,
RepLev1 = (O.merchantreps.any (A = A.levelnumber = = 1)? o.merchantreps.where (A = = A.levelnumber = 1). FirstOrDefault (). Rep.name: ""),
RepLev2 = (O.merchantreps.any (A = A.levelnumber = = 2)? o.merchantreps.where (A = = A.levelnumber = 2). FirstOrDefault (). Rep.name: ""),
RepLev3 = (O.merchantreps.any (A = A.levelnumber = = 3)? o.merchantreps.where (A = = A.levelnumber = 3). FirstOrDefault (). Rep.name: ""),
RepLev4 = (O.merchantreps.any (A = A.levelnumber = = 4)? o.merchantreps.where (A = = A.levelnumber = 4). FirstOrDefault (). Rep.name: ""),
REPLEV5 = (O.merchantreps.any (A = A.levelnumber = = 5)? o.merchantreps.where (A = = A.levelnumber = 5). FirstOrDefault (). Rep.name: ""),
Address1 = O.dbaaddress1,
Address2 = O.dbaaddress2,
City = o.dbacity,
state = O.dbastate,
Zip = O.dbazip,
Ps = (from op in o.products
where Op. Status = = 100
Select New VMPro
{
Efde = Op. Equipmentfee.description,
Ptype = Op. ProductType,
SDe = Op. Software.description
}). ToList ()

});
#endregion

Var sql= (Resultmodel as objectquery<vmb_report>). ToTraceString ();//This sentence is the essence, the view SQL variable is the generated SQL statement.

return Resultmodel;
}

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.