Replies: 3 comments 8 replies
-
这里记录一下踩的一个坑,尽管应该不是bug,不过使用者需要注意。 下面的代码是统计未参加某场考试的学生数, var missingStudentCount = await FreeSql.Select<ClassStudent, TestAnswer>()
.LeftJoin(p => p.t1.StudentNo == p.t2.StudentNo && p.t2.TestID == 1)
.Where(p => new int[]{1,2,3}.Contains(p.t1.ClassId))
.WithTempQuery(p => new { p.t1.StudentNo, p.t2.TAID })
.Where(t => t.TAID == 0)
.CountAsync(); 生成SQL: SELECT count(1) as1
FROM (
SELECT a.[StudentNo], b.[TAID]
FROM [ClassStudent] a
LEFT JOIN [TestAnswer] b ON a.[StudentNo] = b.[StudentNo] AND b.[TestID] = 1
WHERE (((a.[ClassId]) in (1,2,3)) ) a
WHERE (a.[TAID] = 0) 在代码层面TAID是不为Null的int类型,但数据库执行层面,左联后的结果里未匹配行的TAID是 做一点微小修改即可避免此问题: .WithTempQuery(p => new { p.t1.StudentNo, TAID = SqlExt.IsNull(p.t2.TAID, default) }) 生成SQL: SELECT count(1) as1
FROM (
SELECT a.[StudentNo], isnull(b.[TAID], 0) [TAID]
FROM [ClassStudent] a
LEFT JOIN [TestAnswer] b ON a.[StudentNo] = b.[StudentNo] AND b.[TestID] = 1
WHERE (((a.[ClassId]) in (1,2,3))) ) a
WHERE (a.[TAID] = 0) |
Beta Was this translation helpful? Give feedback.
-
请问大佬,WithTempQuery查询Dto属性名相同的问题在3.2.6+的计划中吗? |
Beta Was this translation helpful? Give feedback.
-
this._repo.Orm.Select<TUserLineUpGroup, TUserLineUp, TStaffReservation, TUserSap, TStaffDoctor>() |
Beta Was this translation helpful? Give feedback.
-
需求版本:v3.2.666-preview (最新版本)
文档地址:https://github.com/dotnetcore/FreeSql/wiki/%e5%b5%8c%e5%a5%97%e6%9f%a5%e8%af%a2
目前 API 还未正式确定和发布,这里是征集嵌套查询的相关意见。
如果你有好的想法和建议欢迎发表意见,建议同时提供对应的伪代码,以便大家沟涌。
谢谢大家!
Beta Was this translation helpful? Give feedback.
All reactions