mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
- 修复 HzyTuple 嵌套解析问题;#1390
This commit is contained in:
parent
0ea8cbad8e
commit
4cd57a0afa
@ -54,16 +54,16 @@ namespace FreeSql.Tests.PostgreSQL
|
|||||||
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
|
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
|
||||||
|
|
||||||
var sql = insert.AppendData(items.First()).ToSql();
|
var sql = insert.AppendData(items.First()).ToSql();
|
||||||
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"clicks\", \"title\", \"createtime\") VALUES(@Clicks_0, @Title_0, @CreateTime_0)", sql);
|
Assert.Equal("INSERT INTO \"tb_topic_insert2\"(\"clicks\", \"title\", \"createtime\") VALUES(@Clicks_0, @Title_0, @CreateTime_0)", sql);
|
||||||
|
|
||||||
sql = insert.AppendData(items).ToSql();
|
sql = insert.AppendData(items).ToSql();
|
||||||
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"clicks\", \"title\", \"createtime\") VALUES(@Clicks_0, @Title_0, @CreateTime_0), (@Clicks_1, @Title_1, @CreateTime_1), (@Clicks_2, @Title_2, @CreateTime_2), (@Clicks_3, @Title_3, @CreateTime_3), (@Clicks_4, @Title_4, @CreateTime_4), (@Clicks_5, @Title_5, @CreateTime_5), (@Clicks_6, @Title_6, @CreateTime_6), (@Clicks_7, @Title_7, @CreateTime_7), (@Clicks_8, @Title_8, @CreateTime_8), (@Clicks_9, @Title_9, @CreateTime_9)", sql);
|
Assert.Equal("INSERT INTO \"tb_topic_insert2\"(\"clicks\", \"title\", \"createtime\") VALUES(@Clicks_0, @Title_0, @CreateTime_0), (@Clicks_1, @Title_1, @CreateTime_1), (@Clicks_2, @Title_2, @CreateTime_2), (@Clicks_3, @Title_3, @CreateTime_3), (@Clicks_4, @Title_4, @CreateTime_4), (@Clicks_5, @Title_5, @CreateTime_5), (@Clicks_6, @Title_6, @CreateTime_6), (@Clicks_7, @Title_7, @CreateTime_7), (@Clicks_8, @Title_8, @CreateTime_8), (@Clicks_9, @Title_9, @CreateTime_9)", sql);
|
||||||
|
|
||||||
sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
|
sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
|
||||||
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"title\") VALUES(@Title_0), (@Title_1), (@Title_2), (@Title_3), (@Title_4), (@Title_5), (@Title_6), (@Title_7), (@Title_8), (@Title_9)", sql);
|
Assert.Equal("INSERT INTO \"tb_topic_insert2\"(\"title\") VALUES(@Title_0), (@Title_1), (@Title_2), (@Title_3), (@Title_4), (@Title_5), (@Title_6), (@Title_7), (@Title_8), (@Title_9)", sql);
|
||||||
|
|
||||||
sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql();
|
sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql();
|
||||||
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"clicks\", \"title\") VALUES(@Clicks_0, @Title_0), (@Clicks_1, @Title_1), (@Clicks_2, @Title_2), (@Clicks_3, @Title_3), (@Clicks_4, @Title_4), (@Clicks_5, @Title_5), (@Clicks_6, @Title_6), (@Clicks_7, @Title_7), (@Clicks_8, @Title_8), (@Clicks_9, @Title_9)", sql);
|
Assert.Equal("INSERT INTO \"tb_topic_insert2\"(\"clicks\", \"title\") VALUES(@Clicks_0, @Title_0), (@Clicks_1, @Title_1), (@Clicks_2, @Title_2), (@Clicks_3, @Title_3), (@Clicks_4, @Title_4), (@Clicks_5, @Title_5), (@Clicks_6, @Title_6), (@Clicks_7, @Title_7), (@Clicks_8, @Title_8), (@Clicks_9, @Title_9)", sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -73,10 +73,10 @@ namespace FreeSql.Tests.PostgreSQL
|
|||||||
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
|
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
|
||||||
|
|
||||||
var sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
|
var sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
|
||||||
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"title\") VALUES(@Title_0), (@Title_1), (@Title_2), (@Title_3), (@Title_4), (@Title_5), (@Title_6), (@Title_7), (@Title_8), (@Title_9)", sql);
|
Assert.Equal("INSERT INTO \"tb_topic_insert2\"(\"title\") VALUES(@Title_0), (@Title_1), (@Title_2), (@Title_3), (@Title_4), (@Title_5), (@Title_6), (@Title_7), (@Title_8), (@Title_9)", sql);
|
||||||
|
|
||||||
sql = insert.AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).ToSql();
|
sql = insert.AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).ToSql();
|
||||||
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"clicks\", \"title\") VALUES(@Clicks_0, @Title_0), (@Clicks_1, @Title_1), (@Clicks_2, @Title_2), (@Clicks_3, @Title_3), (@Clicks_4, @Title_4), (@Clicks_5, @Title_5), (@Clicks_6, @Title_6), (@Clicks_7, @Title_7), (@Clicks_8, @Title_8), (@Clicks_9, @Title_9)", sql);
|
Assert.Equal("INSERT INTO \"tb_topic_insert2\"(\"clicks\", \"title\") VALUES(@Clicks_0, @Title_0), (@Clicks_1, @Title_1), (@Clicks_2, @Title_2), (@Clicks_3, @Title_3), (@Clicks_4, @Title_4), (@Clicks_5, @Title_5), (@Clicks_6, @Title_6), (@Clicks_7, @Title_7), (@Clicks_8, @Title_8), (@Clicks_9, @Title_9)", sql);
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void IgnoreColumns()
|
public void IgnoreColumns()
|
||||||
@ -85,10 +85,10 @@ namespace FreeSql.Tests.PostgreSQL
|
|||||||
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
|
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
|
||||||
|
|
||||||
var sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql();
|
var sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql();
|
||||||
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"clicks\", \"title\") VALUES(@Clicks_0, @Title_0), (@Clicks_1, @Title_1), (@Clicks_2, @Title_2), (@Clicks_3, @Title_3), (@Clicks_4, @Title_4), (@Clicks_5, @Title_5), (@Clicks_6, @Title_6), (@Clicks_7, @Title_7), (@Clicks_8, @Title_8), (@Clicks_9, @Title_9)", sql);
|
Assert.Equal("INSERT INTO \"tb_topic_insert2\"(\"clicks\", \"title\") VALUES(@Clicks_0, @Title_0), (@Clicks_1, @Title_1), (@Clicks_2, @Title_2), (@Clicks_3, @Title_3), (@Clicks_4, @Title_4), (@Clicks_5, @Title_5), (@Clicks_6, @Title_6), (@Clicks_7, @Title_7), (@Clicks_8, @Title_8), (@Clicks_9, @Title_9)", sql);
|
||||||
|
|
||||||
sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).ToSql();
|
sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).ToSql();
|
||||||
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"clicks\") VALUES(@Clicks_0), (@Clicks_1), (@Clicks_2), (@Clicks_3), (@Clicks_4), (@Clicks_5), (@Clicks_6), (@Clicks_7), (@Clicks_8), (@Clicks_9)", sql);
|
Assert.Equal("INSERT INTO \"tb_topic_insert2\"(\"clicks\") VALUES(@Clicks_0), (@Clicks_1), (@Clicks_2), (@Clicks_3), (@Clicks_4), (@Clicks_5), (@Clicks_6), (@Clicks_7), (@Clicks_8), (@Clicks_9)", sql);
|
||||||
|
|
||||||
g.pgsql.Delete<TopicIgnore>().Where("1=1").ExecuteAffrows();
|
g.pgsql.Delete<TopicIgnore>().Where("1=1").ExecuteAffrows();
|
||||||
var itemsIgnore = new List<TopicIgnore>();
|
var itemsIgnore = new List<TopicIgnore>();
|
||||||
|
@ -40,7 +40,7 @@ FROM (
|
|||||||
WHERE (ti2.[RefHeadId] = htb.[HeadId] AND ti2.[RefItemId] = htb.[Id])), 0) [RefQuantity]
|
WHERE (ti2.[RefHeadId] = htb.[HeadId] AND ti2.[RefItemId] = htb.[Id])), 0) [RefQuantity]
|
||||||
FROM [bhe_1] a
|
FROM [bhe_1] a
|
||||||
INNER JOIN (
|
INNER JOIN (
|
||||||
SELECT bi.[IsDeleted], bi.[Id], bi.[HeadId], bi.[GoodsId], bi.[Quantity], bi.[RefHeadId], bi.[RefItemId]
|
SELECT bi.[IsDeleted], bi.[Id], bi.[HeadId], bi.[GoodsId], bi.[Quantity], bi.[RefHeadId], bi.[RefItemId], bi.[RefItemComId]
|
||||||
FROM [bie_1] bi
|
FROM [bie_1] bi
|
||||||
WHERE (bi.[IsDeleted] = 0)) htb ON a.[Id] = htb.[HeadId]
|
WHERE (bi.[IsDeleted] = 0)) htb ON a.[Id] = htb.[HeadId]
|
||||||
WHERE (a.[IsDeleted] = 0) ) a
|
WHERE (a.[IsDeleted] = 0) ) a
|
||||||
@ -74,7 +74,7 @@ WHERE (((a.[Id]) in (SELECT DISTINCT v.[Id]
|
|||||||
WHERE (ti2.[RefHeadId] = ht2.[HeadId] AND ti2.[RefItemId] = ht2.[Id])), 0) [RefQuantity]
|
WHERE (ti2.[RefHeadId] = ht2.[HeadId] AND ti2.[RefItemId] = ht2.[Id])), 0) [RefQuantity]
|
||||||
FROM [bhe_1] bh
|
FROM [bhe_1] bh
|
||||||
INNER JOIN (
|
INNER JOIN (
|
||||||
SELECT bi.[IsDeleted], bi.[Id], bi.[HeadId], bi.[GoodsId], bi.[Quantity], bi.[RefHeadId], bi.[RefItemId]
|
SELECT bi.[IsDeleted], bi.[Id], bi.[HeadId], bi.[GoodsId], bi.[Quantity], bi.[RefHeadId], bi.[RefItemId], bi.[RefItemComId]
|
||||||
FROM [bie_1] bi
|
FROM [bie_1] bi
|
||||||
WHERE (bi.[IsDeleted] = 0)) ht2 ON bh.[Id] = ht2.[HeadId]
|
WHERE (bi.[IsDeleted] = 0)) ht2 ON bh.[Id] = ht2.[HeadId]
|
||||||
WHERE (bh.[IsDeleted] = 0) ) v
|
WHERE (bh.[IsDeleted] = 0) ) v
|
||||||
@ -111,7 +111,7 @@ RIGHT JOIN (
|
|||||||
WHERE (ti2.[RefHeadId] = htb.[HeadId] AND ti2.[RefItemId] = htb.[Id])), 0) [RefQuantity]
|
WHERE (ti2.[RefHeadId] = htb.[HeadId] AND ti2.[RefItemId] = htb.[Id])), 0) [RefQuantity]
|
||||||
FROM [bhe_1] a
|
FROM [bhe_1] a
|
||||||
INNER JOIN (
|
INNER JOIN (
|
||||||
SELECT bi.[IsDeleted], bi.[Id], bi.[HeadId], bi.[GoodsId], bi.[Quantity], bi.[RefHeadId], bi.[RefItemId]
|
SELECT bi.[IsDeleted], bi.[Id], bi.[HeadId], bi.[GoodsId], bi.[Quantity], bi.[RefHeadId], bi.[RefItemId], bi.[RefItemComId]
|
||||||
FROM [bie_1] bi
|
FROM [bie_1] bi
|
||||||
WHERE (bi.[IsDeleted] = 0)) htb ON a.[Id] = htb.[HeadId]
|
WHERE (bi.[IsDeleted] = 0)) htb ON a.[Id] = htb.[HeadId]
|
||||||
WHERE (a.[IsDeleted] = 0) ) a
|
WHERE (a.[IsDeleted] = 0) ) a
|
||||||
@ -302,7 +302,7 @@ ORDER BY a.[Date] DESC", sql3);
|
|||||||
.Where(ti => ti.RefHeadId == bi.HeadId && ti.RefItemId == bi.Id)
|
.Where(ti => ti.RefHeadId == bi.HeadId && ti.RefItemId == bi.Id)
|
||||||
.Sum(ti => ti.Quantity) <= bi.Quantity)
|
.Sum(ti => ti.Quantity) <= bi.Quantity)
|
||||||
.ToSql();
|
.ToSql();
|
||||||
Assert.Equal(@"SELECT bi.[IsDeleted], bi.[Id], bi.[HeadId], bi.[GoodsId], bi.[Quantity], bi.[RefHeadId], bi.[RefItemId]
|
Assert.Equal(@"SELECT bi.[IsDeleted], bi.[Id], bi.[HeadId], bi.[GoodsId], bi.[Quantity], bi.[RefHeadId], bi.[RefItemId], bi.[RefItemComId]
|
||||||
FROM [bie_1] bi
|
FROM [bie_1] bi
|
||||||
WHERE (bi.[HeadId] = '62f83a6d-eb53-0608-0097-d177142cadcb' AND bi.[IsDeleted] = 0) AND (isnull((SELECT sum(ti.[Quantity])
|
WHERE (bi.[HeadId] = '62f83a6d-eb53-0608-0097-d177142cadcb' AND bi.[IsDeleted] = 0) AND (isnull((SELECT sum(ti.[Quantity])
|
||||||
FROM [bie_2] ti
|
FROM [bie_2] ti
|
||||||
@ -324,7 +324,7 @@ WHERE (bi.[HeadId] = '62f83a6d-eb53-0608-0097-d177142cadcb' AND bi.[IsDeleted] =
|
|||||||
.ToSql();
|
.ToSql();
|
||||||
Assert.Equal(@"SELECT *
|
Assert.Equal(@"SELECT *
|
||||||
FROM (
|
FROM (
|
||||||
SELECT bi.[Id], bi.[IsDeleted], bi.[Id], bi.[HeadId], bi.[GoodsId], bi.[Quantity], bi.[RefHeadId], bi.[RefItemId], bi.[Quantity], isnull((SELECT sum(ti.[Quantity])
|
SELECT bi.[Id], bi.[IsDeleted], bi.[Id], bi.[HeadId], bi.[GoodsId], bi.[Quantity], bi.[RefHeadId], bi.[RefItemId], bi.[RefItemComId], bi.[Quantity], isnull((SELECT sum(ti.[Quantity])
|
||||||
FROM [bie_2] ti
|
FROM [bie_2] ti
|
||||||
WHERE (ti.[RefHeadId] = bi.[HeadId] AND ti.[RefItemId] = bi.[Id])), 0) [RefQuantity]
|
WHERE (ti.[RefHeadId] = bi.[HeadId] AND ti.[RefItemId] = bi.[Id])), 0) [RefQuantity]
|
||||||
FROM [bie_1] bi
|
FROM [bie_1] bi
|
||||||
@ -375,6 +375,7 @@ WHERE (a.[RefQuantity] < a.[Quantity])", sql2);
|
|||||||
public decimal Quantity { get; set; }
|
public decimal Quantity { get; set; }
|
||||||
public Guid? RefHeadId { get; set; }
|
public Guid? RefHeadId { get; set; }
|
||||||
public Guid? RefItemId { get; set; }
|
public Guid? RefItemId { get; set; }
|
||||||
|
public Guid? RefItemComId { get; set; }
|
||||||
}
|
}
|
||||||
[Table(Name = "bie_1")]
|
[Table(Name = "bie_1")]
|
||||||
class BiEntity1 : BaseItemEntity { }
|
class BiEntity1 : BaseItemEntity { }
|
||||||
@ -382,6 +383,116 @@ WHERE (a.[RefQuantity] < a.[Quantity])", sql2);
|
|||||||
class BiEntity2 : BaseItemEntity { }
|
class BiEntity2 : BaseItemEntity { }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region 2022/12/30
|
||||||
|
abstract class BaseItemComEntity : SoftDelete
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid HeadId { get; set; }
|
||||||
|
public Guid ItemId { get; set; }
|
||||||
|
public int GoodsId { get; set; }
|
||||||
|
public int ComponentId { get; set; }
|
||||||
|
public decimal Quantity { get; set; }
|
||||||
|
public int Level { get; set; }
|
||||||
|
}
|
||||||
|
[Table(Name = "bic_1")]
|
||||||
|
class BicEntity1 : BaseItemComEntity { }
|
||||||
|
[Fact]
|
||||||
|
public void VicDemo20221230()
|
||||||
|
{
|
||||||
|
var fsql = g.mysql;
|
||||||
|
// 逻辑相同 sql1 能够生成 sql2 就会报类型转换错误
|
||||||
|
var sql1 = fsql.Select<BaseItemComEntity>().AsType(typeof(BicEntity1)).As("bic")
|
||||||
|
.Where(bic => bic.Level == 0)
|
||||||
|
.FromQuery(fsql.Select<BaseItemEntity>().AsType(typeof(BiEntity1)).As("bi"))
|
||||||
|
.InnerJoin((bic, bi) => bic.ItemId == bi.Id)
|
||||||
|
.Where((bic, bi) => bi.IsDeleted == false)
|
||||||
|
.WithTempQuery((bic, _) => bic)
|
||||||
|
.FromQuery(fsql.Select<BaseHeadEntity>().AsType(typeof(BhEntity1)).As("bh"))
|
||||||
|
.InnerJoin((bic, bh) => bic.HeadId == bh.Id)
|
||||||
|
.Where((bic, bh) => bh.IsDeleted == false)
|
||||||
|
.WithTempQuery((bic, _) => new
|
||||||
|
{
|
||||||
|
BillItemCom = bic,
|
||||||
|
RefQuantity = fsql.Select<BaseItemEntity>().AsType(typeof(BiEntity1)).As("ti")
|
||||||
|
.Where(ti => ti.RefHeadId == bic.HeadId)
|
||||||
|
.Where(ti => ti.RefItemId == bic.ItemId)
|
||||||
|
.Where(ti => ti.RefItemComId == bic.Id)
|
||||||
|
.Where(ti => ti.IsDeleted == false)
|
||||||
|
.FromQuery(fsql.Select<BaseItemEntity>().AsType(typeof(BiEntity1)))
|
||||||
|
.InnerJoin(ti => ti.t1.HeadId == ti.t2.Id)
|
||||||
|
.Where(ti => ti.t2.IsDeleted == false)
|
||||||
|
.Sum(ti => ti.t1.Quantity),
|
||||||
|
})
|
||||||
|
.Where(v => v.RefQuantity < v.BillItemCom.Quantity)
|
||||||
|
.ToSql();
|
||||||
|
Assert.Equal(@"SELECT *
|
||||||
|
FROM (
|
||||||
|
SELECT a.`IsDeleted`, a.`Id`, a.`HeadId`, a.`ItemId`, a.`GoodsId`, a.`ComponentId`, a.`Quantity`, a.`Level`, ifnull((SELECT sum(ti.`Quantity`)
|
||||||
|
FROM `bie_1` ti
|
||||||
|
INNER JOIN (
|
||||||
|
SELECT a.`IsDeleted`, a.`Id`, a.`HeadId`, a.`GoodsId`, a.`Quantity`, a.`RefHeadId`, a.`RefItemId`, a.`RefItemComId`
|
||||||
|
FROM `bie_1` a) ht2 ON ti.`HeadId` = ht2.`Id`
|
||||||
|
WHERE (ti.`RefHeadId` = a.`HeadId`) AND (ti.`RefItemId` = a.`ItemId`) AND (ti.`RefItemComId` = a.`Id`) AND (ti.`IsDeleted` = 0) AND (ht2.`IsDeleted` = 0)), 0) `RefQuantity`
|
||||||
|
FROM (
|
||||||
|
SELECT bic.`IsDeleted`, bic.`Id`, bic.`HeadId`, bic.`ItemId`, bic.`GoodsId`, bic.`ComponentId`, bic.`Quantity`, bic.`Level`
|
||||||
|
FROM `bic_1` bic
|
||||||
|
INNER JOIN (
|
||||||
|
SELECT bi.`IsDeleted`, bi.`Id`, bi.`HeadId`, bi.`GoodsId`, bi.`Quantity`, bi.`RefHeadId`, bi.`RefItemId`, bi.`RefItemComId`
|
||||||
|
FROM `bie_1` bi) bi ON bic.`ItemId` = bi.`Id`
|
||||||
|
WHERE (bic.`Level` = 0) AND (bi.`IsDeleted` = 0) ) a
|
||||||
|
INNER JOIN (
|
||||||
|
SELECT bh.`IsDeleted`, bh.`Id`, bh.`No`, bh.`Date`
|
||||||
|
FROM `bhe_1` bh) bh ON a.`HeadId` = bh.`Id`
|
||||||
|
WHERE (bh.`IsDeleted` = 0) ) a
|
||||||
|
WHERE (a.`RefQuantity` < a.`Quantity`)", sql1);
|
||||||
|
|
||||||
|
var sql2 = fsql.Select<BaseItemComEntity>().AsType(typeof(BicEntity1))
|
||||||
|
.Where(v => v.Level == 0)
|
||||||
|
.FromQuery(fsql.Select<BaseItemEntity>().AsType(typeof(BiEntity1)))
|
||||||
|
.InnerJoin(v => v.t1.ItemId == v.t2.Id)
|
||||||
|
.Where(v => v.t2.IsDeleted == false)
|
||||||
|
.WithTempQuery(v => v.t1)
|
||||||
|
.FromQuery(fsql.Select<BaseHeadEntity>().AsType(typeof(BhEntity1)))
|
||||||
|
.InnerJoin(v => v.t1.HeadId == v.t2.Id)
|
||||||
|
.Where(v => v.t2.IsDeleted == false)
|
||||||
|
.WithTempQuery(v => new
|
||||||
|
{
|
||||||
|
BillItemCom = v.t1,
|
||||||
|
RefQuantity = fsql.Select<BaseItemEntity>().AsType(typeof(BiEntity1)).As("ti")
|
||||||
|
.Where(ti => ti.RefHeadId == v.t1.HeadId)
|
||||||
|
.Where(ti => ti.RefItemId == v.t1.ItemId)
|
||||||
|
.Where(ti => ti.RefItemComId == v.t1.Id)
|
||||||
|
.Where(ti => ti.IsDeleted == false)
|
||||||
|
.FromQuery(fsql.Select<BaseItemEntity>().AsType(typeof(BiEntity1)))
|
||||||
|
.InnerJoin(ti => ti.t1.HeadId == ti.t2.Id)
|
||||||
|
.Where(ti => ti.t2.IsDeleted == false)
|
||||||
|
.Sum(ti => ti.t1.Quantity),
|
||||||
|
})
|
||||||
|
.Where(v => v.RefQuantity < v.BillItemCom.Quantity)
|
||||||
|
.ToSql();
|
||||||
|
Assert.Equal(@"SELECT *
|
||||||
|
FROM (
|
||||||
|
SELECT a.`IsDeleted`, a.`Id`, a.`HeadId`, a.`ItemId`, a.`GoodsId`, a.`ComponentId`, a.`Quantity`, a.`Level`, ifnull((SELECT sum(ti.`Quantity`)
|
||||||
|
FROM `bie_1` ti
|
||||||
|
INNER JOIN (
|
||||||
|
SELECT a.`IsDeleted`, a.`Id`, a.`HeadId`, a.`GoodsId`, a.`Quantity`, a.`RefHeadId`, a.`RefItemId`, a.`RefItemComId`
|
||||||
|
FROM `bie_1` a) ht2 ON ti.`HeadId` = ht2.`Id`
|
||||||
|
WHERE (ti.`RefHeadId` = a.`HeadId`) AND (ti.`RefItemId` = a.`ItemId`) AND (ti.`RefItemComId` = a.`Id`) AND (ti.`IsDeleted` = 0) AND (ht2.`IsDeleted` = 0)), 0) `RefQuantity`
|
||||||
|
FROM (
|
||||||
|
SELECT a.`IsDeleted`, a.`Id`, a.`HeadId`, a.`ItemId`, a.`GoodsId`, a.`ComponentId`, a.`Quantity`, a.`Level`
|
||||||
|
FROM `bic_1` a
|
||||||
|
INNER JOIN (
|
||||||
|
SELECT a.`IsDeleted`, a.`Id`, a.`HeadId`, a.`GoodsId`, a.`Quantity`, a.`RefHeadId`, a.`RefItemId`, a.`RefItemComId`
|
||||||
|
FROM `bie_1` a) htb ON a.`ItemId` = htb.`Id`
|
||||||
|
WHERE (a.`Level` = 0) AND (htb.`IsDeleted` = 0) ) a
|
||||||
|
INNER JOIN (
|
||||||
|
SELECT a.`IsDeleted`, a.`Id`, a.`No`, a.`Date`
|
||||||
|
FROM `bhe_1` a) htb ON a.`HeadId` = htb.`Id`
|
||||||
|
WHERE (htb.`IsDeleted` = 0) ) a
|
||||||
|
WHERE (a.`RefQuantity` < a.`Quantity`)", sql2);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void SingleTablePartitionBy()
|
public void SingleTablePartitionBy()
|
||||||
{
|
{
|
||||||
|
@ -2320,12 +2320,14 @@ namespace FreeSql.Internal
|
|||||||
{
|
{
|
||||||
private List<SelectTableInfo> tables;
|
private List<SelectTableInfo> tables;
|
||||||
private ParameterExpression[] parameters;
|
private ParameterExpression[] parameters;
|
||||||
|
private ParameterExpression lambdaHzyParameter;
|
||||||
public LambdaExpression Modify(LambdaExpression lambda, List<SelectTableInfo> tables)
|
public LambdaExpression Modify(LambdaExpression lambda, List<SelectTableInfo> tables)
|
||||||
{
|
{
|
||||||
this.tables = tables.Where(a => a.Type != SelectTableInfoType.Parent).ToList();
|
this.tables = tables.Where(a => a.Type != SelectTableInfoType.Parent).ToList();
|
||||||
parameters = this.tables.Select(a => a.Parameter ??
|
parameters = this.tables.Select(a => a.Parameter ??
|
||||||
Expression.Parameter(a.Table.Type,
|
Expression.Parameter(a.Table.Type,
|
||||||
a.Alias.StartsWith("SP10") ? a.Alias.Replace("SP10", "ht") : a.Alias)).ToArray();
|
a.Alias.StartsWith("SP10") ? a.Alias.Replace("SP10", "ht") : a.Alias)).ToArray();
|
||||||
|
lambdaHzyParameter = lambda.Parameters.FirstOrDefault();
|
||||||
var exp = Visit(lambda.Body);
|
var exp = Visit(lambda.Body);
|
||||||
return Expression.Lambda(exp, parameters);
|
return Expression.Lambda(exp, parameters);
|
||||||
}
|
}
|
||||||
@ -2338,6 +2340,7 @@ namespace FreeSql.Internal
|
|||||||
var parent = node.Expression as MemberExpression;
|
var parent = node.Expression as MemberExpression;
|
||||||
if (parent.Expression?.NodeType == ExpressionType.Parameter &&
|
if (parent.Expression?.NodeType == ExpressionType.Parameter &&
|
||||||
parent.Expression.Type.Name.StartsWith("HzyTuple`") == true &&
|
parent.Expression.Type.Name.StartsWith("HzyTuple`") == true &&
|
||||||
|
parent.Expression == lambdaHzyParameter &&
|
||||||
int.TryParse(parent.Member.Name.Replace("t", ""), out widx) && widx > 0 && widx <= tables.Count)
|
int.TryParse(parent.Member.Name.Replace("t", ""), out widx) && widx > 0 && widx <= tables.Count)
|
||||||
{
|
{
|
||||||
if (parameters[widx - 1].Type != parent.Type) //解决 BaseEntity + AsTable 时报错
|
if (parameters[widx - 1].Type != parent.Type) //解决 BaseEntity + AsTable 时报错
|
||||||
@ -2348,6 +2351,7 @@ namespace FreeSql.Internal
|
|||||||
|
|
||||||
if (node.Expression?.NodeType == ExpressionType.Parameter &&
|
if (node.Expression?.NodeType == ExpressionType.Parameter &&
|
||||||
node.Expression.Type.Name.StartsWith("HzyTuple`") == true &&
|
node.Expression.Type.Name.StartsWith("HzyTuple`") == true &&
|
||||||
|
node.Expression == lambdaHzyParameter &&
|
||||||
int.TryParse(node.Member.Name.Replace("t", ""), out widx) && widx > 0 && widx <= tables.Count)
|
int.TryParse(node.Member.Name.Replace("t", ""), out widx) && widx > 0 && widx <= tables.Count)
|
||||||
{
|
{
|
||||||
if (parameters[widx - 1].Type != node.Type) //解决 BaseEntity + AsTable 时报错
|
if (parameters[widx - 1].Type != node.Type) //解决 BaseEntity + AsTable 时报错
|
||||||
|
Loading…
x
Reference in New Issue
Block a user