mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 12:28:15 +08:00
- 修复 子查询内使用嵌套查询 bug;#1215
This commit is contained in:
@ -34,14 +34,14 @@ namespace FreeSql.Tests.SqlServer
|
||||
FROM [bhe_1] a
|
||||
WHERE (a.Id IN (SELECT a.[Id] as1
|
||||
FROM (
|
||||
SELECT a.[IsDeleted], a.[Id], a.[No], a.[Date], SP10b.[Quantity], isnull((SELECT sum(ti2.[Quantity])
|
||||
SELECT a.[IsDeleted], a.[Id], a.[No], a.[Date], htb.[Quantity], isnull((SELECT sum(ti2.[Quantity])
|
||||
FROM [bie_2] ti2
|
||||
WHERE (ti2.[RefHeadId] = SP10b.[HeadId] AND ti2.[RefItemId] = SP10b.[Id])), 0) [RefQuantity]
|
||||
WHERE (ti2.[RefHeadId] = htb.[HeadId] AND ti2.[RefItemId] = htb.[Id])), 0) [RefQuantity]
|
||||
FROM [bhe_1] a
|
||||
INNER JOIN (
|
||||
SELECT bi.[IsDeleted], bi.[Id], bi.[HeadId], bi.[GoodsId], bi.[Quantity], bi.[RefHeadId], bi.[RefItemId]
|
||||
FROM [bie_1] bi
|
||||
WHERE (bi.[IsDeleted] = 0)) SP10b ON a.[Id] = SP10b.[HeadId]
|
||||
WHERE (bi.[IsDeleted] = 0)) htb ON a.[Id] = htb.[HeadId]
|
||||
WHERE (a.[IsDeleted] = 0) ) a
|
||||
WHERE (a.[RefQuantity] < a.[Quantity])
|
||||
GROUP BY a.[Id]))
|
||||
@ -68,14 +68,14 @@ ORDER BY a.[Date] DESC", sql1);
|
||||
FROM [bhe_1] a
|
||||
WHERE (((a.[Id]) in (SELECT DISTINCT v.[Id]
|
||||
FROM (
|
||||
SELECT ht1.[IsDeleted], ht1.[Id], ht1.[No], ht1.[Date], ht2.[Quantity], isnull((SELECT sum(ti2.[Quantity])
|
||||
SELECT bh.[IsDeleted], bh.[Id], bh.[No], bh.[Date], ht2.[Quantity], isnull((SELECT sum(ti2.[Quantity])
|
||||
FROM [bie_2] ti2
|
||||
WHERE (ti2.[RefHeadId] = ht2.[HeadId] AND ti2.[RefItemId] = ht2.[Id])), 0) [RefQuantity]
|
||||
FROM [bhe_1] ht1
|
||||
FROM [bhe_1] bh
|
||||
INNER JOIN (
|
||||
SELECT bi.[IsDeleted], bi.[Id], bi.[HeadId], bi.[GoodsId], bi.[Quantity], bi.[RefHeadId], bi.[RefItemId]
|
||||
FROM [bie_1] bi
|
||||
WHERE (bi.[IsDeleted] = 0)) ht2 ON ht1.[Id] = ht2.[HeadId]
|
||||
WHERE (bi.[IsDeleted] = 0)) ht2 ON bh.[Id] = ht2.[HeadId]
|
||||
WHERE (bh.[IsDeleted] = 0) ) v
|
||||
WHERE (v.[RefQuantity] < v.[Quantity]))))
|
||||
ORDER BY a.[Date] DESC", sql2);
|
||||
@ -99,8 +99,8 @@ ORDER BY a.[Date] DESC", sql2);
|
||||
)
|
||||
.RightJoin(v => v.t1.Id == v.t2.Id)
|
||||
.OrderByDescending(v => v.t1.Date)
|
||||
.ToSql();
|
||||
Assert.Equal(@"SELECT *
|
||||
.ToSql(v => v.t1);
|
||||
Assert.Equal(@"SELECT a.[IsDeleted] as1, a.[Id] as2, a.[No] as3, a.[Date] as4
|
||||
FROM [bhe_1] a
|
||||
RIGHT JOIN (
|
||||
SELECT DISTINCT a.[Id]
|
||||
@ -115,7 +115,28 @@ RIGHT JOIN (
|
||||
WHERE (bi.[IsDeleted] = 0)) htb ON a.[Id] = htb.[HeadId]
|
||||
WHERE (a.[IsDeleted] = 0) ) a
|
||||
WHERE (a.[RefQuantity] < a.[Quantity]) ) htb ON a.[Id] = htb.[Id]
|
||||
ORDER BY a.[Date] DESC;", sql3);
|
||||
ORDER BY a.[Date] DESC", sql3);
|
||||
|
||||
fsql.Select<BaseHeadEntity>().AsType(typeof(BhEntity1))
|
||||
.FromQuery(
|
||||
fsql.Select<BaseHeadEntity>().AsType(typeof(BhEntity1)).Where(bh => bh.IsDeleted == false)
|
||||
.FromQuery(fsql.Select<BaseItemEntity>().AsType(typeof(BiEntity1)).As("bi").Where(bi => bi.IsDeleted == false))
|
||||
.InnerJoin(v => v.t1.Id == v.t2.HeadId)
|
||||
.WithTempQuery(v => new
|
||||
{
|
||||
BillHead = v.t1,
|
||||
Quantity = v.t2.Quantity,
|
||||
RefQuantity = fsql.Select<BaseItemEntity>().AsType(typeof(BiEntity2)).As("bi2")
|
||||
.Where(ti2 => ti2.RefHeadId == v.t2.HeadId && ti2.RefItemId == v.t2.Id)
|
||||
.Sum(ti2 => ti2.Quantity),
|
||||
})
|
||||
.Where(v => v.RefQuantity < v.Quantity)
|
||||
.Distinct()
|
||||
.WithTempQuery(v => new { v.BillHead.Id })
|
||||
)
|
||||
.RightJoin(v => v.t1.Id == v.t2.Id)
|
||||
.OrderByDescending(v => v.t1.Date)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
Reference in New Issue
Block a user