问题描述
- linq语句优化(各位仔细看一下)
-
#region linq方式(待优化)
if (RoleTyp == 3)//大农户
{
if (IsClosed == 0)//进行中
{
IList demandList =
(from d in dbContext.T_FARMER_PUBLISHED_DEMAND
join u in dbContext.T_USER
on d.CreateUserId equals u.Id
join s in dbContext.T_SYS_DICTIONARY on d.DemandTypeId equals s.Code
where d.PublishStateId == 0
orderby d.CreateTime descending
select new PublishedDemandRepositoryModel
{
Name = s.DisplayName,
PublishedDate = d.CreateTime,
Status = d.PublishStateId,
Address = d.Province + "" + d.City + "" + d.Region + "" + d.Township + "" + d.Village,
DetailAddress = d.DetailedAddress,
RequirementType = s.DisplayName,
PhoneNumber = u.PhoneNumber,
Remark = d.Brief
}).Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();
return demandList;
}
else//已关闭
{
IList demandList = (from d in dbContext.T_FARMER_PUBLISHED_DEMAND
join u in dbContext.T_USER
on d.CreateUserId equals u.Id
join s in dbContext.T_SYS_DICTIONARY on d.DemandTypeId equals s.Code
where d.PublishStateId != 0
orderby d.CreateTime descending
select new PublishedDemandRepositoryModel
{
Name = s.DisplayName,
PublishedDate = d.CreateTime,
Status = d.PublishStateId,
Address = d.Province + "" + d.City + "" + d.Region + "" + d.Township + "" + d.Village,
DetailAddress = d.DetailedAddress,
RequirementType = s.DisplayName,
PhoneNumber = u.PhoneNumber,
Remark = d.Brief
}).Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();
return demandList;
}} else if (RoleTyp == 5) //产业商 { if (IsClosed == 0)//进行中 { IList<PublishedDemandRepositoryModel> demandList = (from d in dbContext.T_BUSINESS_PUBLISHED_DEMAND join u in dbContext.T_USER on d.CreateUserId equals u.Id join s in dbContext.T_SYS_DICTIONARY on d.DemandTypeId equals s.Code where d.PublishStateId == 0 orderby d.CreateTime descending select new PublishedDemandRepositoryModel { Name = s.DisplayName, PublishedDate = d.CreateTime, Status = d.PublishStateId, Address = d.Province + "" + d.City + "" + d.Region + "" + d.Township + "" + d.Village, DetailAddress = d.DetailedAddress, RequirementType = s.DisplayName, PhoneNumber = u.PhoneNumber, Remark = d.Brief }).Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList(); return demandList; } else//已关闭 { IList<PublishedDemandRepositoryModel> demandList = (from d in dbContext.T_BUSINESS_PUBLISHED_DEMAND join u in dbContext.T_USER on d.CreateUserId equals u.Id join s in dbContext.T_SYS_DICTIONARY on d.DemandTypeId equals s.Code where d.PublishStateId !=0 orderby d.CreateTime descending select new PublishedDemandRepositoryModel { Name = s.DisplayName, PublishedDate = d.CreateTime, Status = d.PublishStateId, Address = d.Province + "" + d.City + "" + d.Region + "" + d.Township + "" + d.Village, DetailAddress = d.DetailedAddress, RequirementType = s.DisplayName, PhoneNumber = u.PhoneNumber, Remark = d.Brief }).Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList(); return demandList; } } else { return null; } #endregion
解决方案
别人写的代码,仔细看几遍也看不懂~~~~不熟悉你的业务,何况这么多代码,看都看晕了啊!
解决方案二:
这代码写的该有多臭,哥们都看看书吧
时间: 2024-12-10 13:05:47