select时,SqlFunc.IIF不能用来判断是否子查询或返回null吗 返回

SqlSugar 处理完成
3 196
该叫什么   发布于1个月前
悬赏:0 飞吻

lessonEntryRecord字段是一个实体类型,直接子查询没有问题

.Select(p => new LessonInfoDto()
{
    Id = p.Id,
    lessonEntryRecord = SqlFunc.IIF(memberType > 0, SqlFunc.Subqueryable<LessonEntryRecord>().Where(c => c.LessonId == p.Id && c.MemberId == param.MemberId.Value
                && c.EntryState == (int)LessonEntryEnum.EntryStateEnum.BMCG && c.RefundState == (int)LessonEntryEnum.ReturnStateEnum.WTH).First(), null),
});

使用SqlFunc.IIF后 ,生成的sql不对

SELECT  [Id] AS [Id] 
, [MemberId] AS [LessonEntryRecord.MemberId] 
, [LessonId] AS [LessonEntryRecord.LessonId]
FROM [LessonInfo] [p]  WHERE ( [Id] > 0 )

这样会报错 没有MemberId和LessonId字段

热忱回答3