Linq加入查询

时间:2014-10-30 09:30:36

标签: linq

有人可以用最简单的方式重构我的代码吗?

var yearly = context.Prospects.Join(context.Prospect_Details, prospect => prospect.ProspectId,
                    prosDetail => prosDetail.ProspectID,
                    (prospect, prosDetail) => new {Prospect = prospect, ProspectDetail = prosDetail})
                    .Join(context.Sources, prospect => prospect.Prospect.SourceId, source => source.SourceId, (prospect, source) => new {Prospect = prospect, Source = source})
                    .Where(
                        c =>
                            c.Prospect.Prospect.Customer.StoreId == storeid && c.Prospect.ProspectDetail.IsDeleted == false
                            && c.Prospect.ProspectDetail.DateCreated.Year == date.Year && c.Prospect.Prospect.Customer.IsMerge == null
                            && c.Prospect.Prospect.SubStatus.Status.Name == "Sold").ToList();

            var daily = context.Prospects.Join(context.Prospect_Details, prospect => prospect.ProspectId,
                    prosDetail => prosDetail.ProspectID,
                    (prospect, prosDetail) => new { Prospect = prospect, ProspectDetail = prosDetail })
                    .Join(context.Sources, prospect => prospect.Prospect.SourceId, source => source.SourceId, (prospect, source) => new { Prospect = prospect, Source = source })
                    .Where(
                        c =>
                            c.Prospect.Prospect.Customer.StoreId == storeid && c.Prospect.ProspectDetail.IsDeleted == false
                            && c.Prospect.ProspectDetail.DateCreated.Year == date.Year && c.Prospect.ProspectDetail.DateCreated.Month == date.Month
                            && c.Prospect.ProspectDetail.DateCreated.Day == date.Day && c.Prospect.Prospect.Customer.IsMerge == null
                            && c.Prospect.Prospect.SubStatus.Status.Name == "Sold").ToList();

我需要知道是否有一种最简单的方法,即linq-sql中的新手。

0 个答案:

没有答案