导航查询筛选的问题 返回
Includes里面加了where/whereIF,select里面直接x.Disclosures.Count没有Includes里面的筛选条件,这样是否正常
热忱回答(15)
-
fate sta VIP01周前
这里面 的any改成 any(三元表达式)
0 回复 -
x VIP01周前
这样不行啊。。。或者不是这样写?
0 回复 -
fate sta VIP01周前
发文本 截图没办法改
0 回复 -
x VIP01周前
RefAsync<int> total = 0;
var current = OperatorProvider.Provider.GetCurrent();
var roleCode = current?.RoleCode;
var orgId = current?.OrgId;
var list = await base.ChangeRepository<BaseRepository<PipelineProject>>().Queryable()
.Includes(x => x.Disclosures.WhereIF(roleCode == RoleCode.Company.ToString(), s => s.OrgId == orgId).ToList())
.LeftJoin<SysOrgnazation>((x, o) => x.ParentOrgId == o.Id)
.LeftJoin<PipelineType>((x, o, t) => x.PipelineType == t.PipelineTypeCode)
.WhereIF(input.ProjectName.IsNotNullOrWhiteSpace(), x => SqlFunc.Contains(x.ProjectName, input.ProjectName))
.WhereIF(input.ParentOrgId.IsNotNullOrWhiteSpace(), x => x.ParentOrgId == input.ParentOrgId)
.WhereIF(input.PipelineType.IsNotNullOrWhiteSpace(), x => x.PipelineType == input.PipelineType)
.WhereIF(input.HaveData == true, x => x.Disclosures.Any(s => roleCode == RoleCode.Company.ToString() ? s.OrgId == orgId : 1 == 1))
.WhereIF(input.HaveData == false, x => !x.Disclosures.Any(s => roleCode == RoleCode.Company.ToString() ? s.OrgId == orgId : 1 == 1))
//.WhereIF(input.CheckState is not null && input.CheckState == CheckState.NoCheck, x => !SqlFunc.Exists(x.DisclosureCheck.Id))
//.WhereIF(input.CheckState is not null && input.CheckState != CheckState.NoCheck, x => x.DisclosureCheck.CheckState == input.CheckState)
.OrderByDescending(x => x.CreateTime)
.Select((x, o, t) => new PipelineProjectDisclosureViewModel()
{
Id = x.Id,
ProjectName = x.ProjectName,
ParentOrgName = o.OrgName,
PipelineTypeName = t.PipelineTypeName,
Disclosures = x.Disclosures,
DataCount = x.Disclosures.Count(s => roleCode == RoleCode.Company.ToString() ? s.OrgId == orgId : 1 == 1),
//CheckState = x.DisclosureCheck.CheckState,
//CheckStateName = SqlFunc.IIF(x.DisclosureCheck.Id == null, "待提交", SqlFunc.IsNull(x.DisclosureCheck.WaitCheckType, "") + x.DisclosureCheck.CheckStateInfo.DicName),
})
.ToPageListAsync(input.PageIndex, input.PageSize, total);
0 回复 -
fate sta VIP01周前
.WhereIF(input.HaveData == true, x => x.Disclosures.Any(s => roleCode == RoleCode.Company.ToString() ? s.OrgId == orgId ?true:false: true))
.WhereIF(input.HaveData == false, x => !x.Disclosures.Any(s => roleCode == RoleCode.Company.ToString() ? s.OrgId == orgId ?true:false: true))
改成这样
0 回复 -
x VIP01周前
震惊
0 回复 -
x VIP01周前
SELECT COUNT
( 1 )
FROM
(
SELECT
[x].[Id] AS [Id],
[x].[ProjectName] AS [ProjectName],
[o].[OrgName] AS [ParentOrgName],
[t].[PipelineTypeName] AS [PipelineTypeName],
[x].[Id] AS SugarNav_Id
FROM
(
SELECT
*
FROM
(
SELECT
[ProjectNo],
[ProjectName],
[ParentOrgId],
[ParentOrgCode],
[OrgId],
[Street],
[Source],
[RoadExcavate],
[道路挖掘许可编号],
[建设工程规划许可编号],
[建设工程施工许可编号],
[ApplicationOrgId],
[ApplicationOrgName],
[ApplicationOperator],
[ApplicationOperatorContacts],
[BuildingOrgId],
[BuildingOrgCode],
[BuildingOrgName],
[BuildingPrincipal],
[BuildingPrincipalContacts],
[ConstructionOrgId],
[ConstructionOrgCode],
[ConstructionOrgName],
[ConstructionPerson],
[ConstructionPersonPhone],
[ControlUnit],
[ControlPerson],
[ControlPersonPhone],
[ProjectType],
[PipelineType],
[地块名],
[PipelineDiameter],
[PipelineDiameterUnit],
[PipelineLength],
[PipelineLengthUnit],
[PipelineDepth],
[PipelineDepthUnit],
[PipelineHolesCount],
[PipelineHolesCountUnit],
[EstimatedExcavateArea],
[EstimatedExcavateAreaUnit],
[EstimatedStartTime],
[EstimatedEndTime],
[ActualStartTime],
[ActualEndTime],
[AcceptanceDate],
[ApproveDate],
[Approver],
[ProjectStatus],
[ConstructionArt],
[X],
[Y],
[ConstructionAddress],
[IsDelete],
[DeleteTime],
[DeleteUserId],
[CreateTime],
[CreateUserId],
[LastModifyTime],
[LastModifyUserId],
[Id]
FROM
[PipelineProject]
WHERE
1 = 1
AND ( [IsDelete] = 0 )
) MergeTable
) [x]
LEFT JOIN [SysOrgnazation] [o] ON ( [x].[ParentOrgId] = [o].[Id] )
AND ( [o].[IsDelete] = 0 )
LEFT JOIN [PipelineType] [t] ON ( [x].[PipelineType] = [t].[PipelineTypeCode] )
AND ( [t].[IsDelete] = 0 )
WHERE
(
EXISTS (
SELECT
1
FROM
[PipelineProjectDisclosure] [s]
WHERE
( [IsDelete] = 0 )
AND (
CASE
WHEN ( N'Company' = CAST ( N'Company' AS NVARCHAR ( MAX ) ) ) THEN
( CASE WHEN ( [s].[OrgId] = N'211a591e29144e36bd07a5b8aaec5063' ) THEN 1 ELSE 0 END ) ELSE 1
END
)
AND [PipelineProjectId] = [x].[Id]
)
)
AND ( [x].[IsDelete] = 0 )
) CountTable
[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]在应使用条件的上下文(在 'AND' 附近)中指定了非布尔类型的表达式。 (4145)
这么写不行,和我的写法生成的sql语句是一样的
0 回复 -
fate sta VIP01周前
https://www.donet5.com/Home/Doc?typeId=2366
按提问模版写个简单的可以重现的DEMO
0 回复 -
x VIP01周前0 回复
-
x VIP06天前
我要沉下去了
0 回复 -
fate sta VIP06天前
@x:好的我这边处理
0 回复 -
fate sta VIP06天前
var list2 = db.Queryable<A>() .Select(x => new { aname = x.name, bcount = x.blist.Count(s=> rolecode == "code1"&& s.orgid == orgid||rolecode != "code1")//这样等于同CountIF }) .ToList();
0 回复 -
fate sta VIP06天前
只查询count不需要 Includes
0 回复 -
x VIP06天前
.WhereIF(haveData == true, x => x.blist.Any(s => rolecode == "code1" && s.orgid == orgid || rolecode != "code1")))
.WhereIF(haveData == false, x => !x.blist.Any(s => rolecode == "code1"&& s.orgid == orgid||rolecode != "code1")))
这种有没有合并的写法?类似于
.WhereIF(haveData != null, x => x.blist.Any(s => rolecode == "code1"&& s.orgid == orgid||rolecode != "code1")) == havaData)但我这样写是有问题的
0 回复 -
fate sta VIP06天前
看一下文档:动态表达式
WhereIF(haveData != null, x => x.blist.Any(动态表达式))
0 回复