一句话,将Linq语句转换为Sql语句



   public IEnumerable<VMB_Report> ReportView_List(VMB_ReportConditions requiredModel)
        {
          
            IEnumerable<VMB_Report> resultModel = new List<VMB_Report>();
         IQueryable<Merchant> merchantList;

              merchantList = Report_List();
          

            #region 从MerchantList中获取VMB_Report集合


            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();//此句为精华,查看sql变量就是生成的sql语句。

          return resultModel;
        }

一句话,将Linq语句转换为Sql语句,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。