子查询中不能写whereif,可以用什么方式来替代呢 返回
temp = SqlSugarHelper.Db.Queryable<McsLotLock>()
.LeftJoin<SysUserInfo>((a, b) => a.CreateUserId == b.UserId)
.LeftJoin<SysUserInfo>((a, b, c) => a.UpdateUserId == c.UserId)
.LeftJoin<IerpOrgInfo>((a, b, c, d) => a.OrgId == d.OrgId)
.WhereIF(lockSearchDto.OrgId != null, (a, b, c, d) => a.OrgId == lockSearchDto.OrgId)
.WhereIF(!string.IsNullOrEmpty(lockSearchDto.ItemNo), (a, b, c, d) => a.ItemNo.Contains(lockSearchDto.ItemNo!))
.WhereIF(!string.IsNullOrEmpty(lockSearchDto.StartDate) && !string.IsNullOrEmpty(lockSearchDto.EndDate),
(a, b, c, d) => SqlFunc.Between(a.CreateDate, Convert.ToDateTime(lockSearchDto.StartDate), Convert.ToDateTime(lockSearchDto.EndDate)))
.Select((a, b, c, d) => new McsLotLockDto()
{
LockId = a.LockId,
ItemNo = a.ItemNo,
LotNo = a.LotStart,
LockStatus = a.LockStatus,
Remarks = a.Remarks,
CreateUserId = a.CreateUserId,
CreateUser = string.IsNullOrEmpty(b.UserNo) ? string.Empty : $"({b.UserNo}){b.UserNameCh}",
CreateDate = a.CreateDate,
UpdateUserId = a.UpdateUserId,
UpdateUser = string.IsNullOrEmpty(c.UserNo) ? string.Empty : $"({c.UserNo}){c.UserNameCh}",
UpdateDate = a.UpdateDate,
DateCode = a.DateCodeStart,
SpecialWipNo = a.SpecialWipNo,
OrgNo = d.OrgNo,
OrgId = a.OrgId,
InspectionQty = SqlFunc.Subqueryable<IqaHeader>()
.Where(x => x.OrgId == a.OrgId
&& x.ItemNo == a.ItemNo && a.LockStatus == "Y"
&& SqlFunc.Between(x.CreateDate, a.CreateDate, DateTime.Now))
.WhereIF(!string.IsNullOrEmpty(a.DateCodeStart), x => a.DateCodeStart.Contains(x.DateCode))
.WhereIF(!string.IsNullOrEmpty(a.LotStart), x => a.LotStart.Contains(x.LotNo)).Count(),
IssuedQty = SqlFunc.Subqueryable<WmsTrans>()
.Where(t => t.OrgId == a.OrgId && t.ItemNo == a.ItemNo && a.LockStatus == "Y" && t.TransactionTypeId == 35
&& SqlFunc.Between(t.CreateDate, a.CreateDate, DateTime.Now))
.WhereIF(!string.IsNullOrEmpty(a.DateCodeStart), t => a.DateCodeStart.Contains(t.DateCode))
.WhereIF(!string.IsNullOrEmpty(a.LotStart), t => a.LotStart.Contains(t.LotNo)).Count()
})
.MergeTable()
.OrderBy(a => a.CreateUser, OrderByType.Desc)
.ToPageList(lockSearchDto.PageIndex, lockSearchDto.PageSize, ref totalCount);
报错:
中文提示 : Subquery.WhereIF 第一个参数不支持表达式中的变量,只支持外部变量
English Message : Subquery.WhereIF.IsWhere Not(IsNullOrEmpty(a.LotStart)) not supported
热忱回答(3)
-
fate sta VIP0
2025/8/28用三元表达式不用whereif
0 回复 -
fate sta VIP0
2025/8/28whereif第一个参数只能是变量
0 回复 -
figther VIP0
2025/8/29我使用where用了三元表达式,现在可以了,感谢感谢
0 回复