码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2014-07-30 17:42:44      阅读:307      评论:0      收藏:0      [点我收藏+]

标签: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语句,布布扣,bubuko.com

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

标签:linq 转换成sql 语句

原文地址:http://blog.csdn.net/haiyangzhibing/article/details/38300749

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!