PgSql BUG

This commit is contained in:
sunkaixuna 2021-08-16 22:45:16 +08:00
parent b7215b7e83
commit 8cdfa98749
4 changed files with 206 additions and 1 deletions

View File

@ -52,6 +52,94 @@ namespace OrmTest
//Use Lock
db.Insertable(insertObj).With(SqlWith.UpdLock).ExecuteCommand();
db.CodeFirst.InitTables<RootTable0, TwoItem, TwoItem2, TwoItem3>();
db.CodeFirst.InitTables<ThreeItem2>();
db.DbMaintenance.TruncateTable("RootTable0");
db.DbMaintenance.TruncateTable("TwoItem");
db.DbMaintenance.TruncateTable("TwoItem2");
db.DbMaintenance.TruncateTable("TwoItem3");
db.DbMaintenance.TruncateTable("ThreeItem2");
Console.WriteLine("SubInsert Start");
db.Insertable(new Order()
{
Name = "订单 1",
CustomId = 1,
Price = 100,
CreateTime = DateTime.Now,
Id = 0,
Items = new List<OrderItem>() {
new OrderItem(){
CreateTime=DateTime.Now,
OrderId=0,
Price=1,
ItemId=1
},
new OrderItem(){
CreateTime=DateTime.Now,
OrderId=0,
Price=2,
ItemId=2
}
}
})
.AddSubList(it => it.Items.First().OrderId).ExecuteCommand();
db.Insertable(new List<RootTable0>() {
new RootTable0()
{
Name="aa",
TwoItem2=new TwoItem2() {
Id="1",
ThreeItem2=new List<ThreeItem2>(){
new ThreeItem2(){ Name="a", TwoItem2Id="1" },
new ThreeItem2(){ Id=2, Name="a2", TwoItem2Id="2" }
}
},
TwoItem=new TwoItem()
{
Name ="itema" ,
RootId=2
},
TwoItem3=new List<TwoItem3>(){
new TwoItem3(){ Id=0, Name="a",Desc="" },
}
},
new RootTable0()
{
Name="bb",
TwoItem2=new TwoItem2() {
Id="2"
},
TwoItem=new TwoItem()
{
Name ="itemb" ,
RootId=2,
},
TwoItem3=new List<TwoItem3>(){
new TwoItem3(){ Id=1, Name="b",Desc="" },
new TwoItem3(){ Id=2, Name="b1",Desc="1" },
}
}
})
.AddSubList(it => it.TwoItem.RootId)
.AddSubList(it => new SubInsertTree()
{
Expression = it.TwoItem2.RootId,
ChildExpression = new List<SubInsertTree>() {
new SubInsertTree(){
Expression=it.TwoItem2.ThreeItem2.First().TwoItem2Id
}
}
})
.AddSubList(it => it.TwoItem3)
.ExecuteCommand();
Console.WriteLine("#### Insertable End ####");
}
}

View File

@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
public class RootTable0
{
[SqlSugar.SugarColumn(IsPrimaryKey =true,IsIdentity =true)]
public int Id { get; set; }
public string Name { get; set; }
[SqlSugar.SugarColumn(IsIgnore =true)]
public TwoItem TwoItem { get; set; }
[SqlSugar.SugarColumn(IsIgnore = true)]
public TwoItem2 TwoItem2 { get; set; }
[SqlSugar.SugarColumn(IsIgnore = true)]
public List<TwoItem3> TwoItem3 { get; set; }
}
public class TwoItem
{
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public int RootId { get; set; }
public string Name { get; set; }
}
public class TwoItem2
{
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
public string Id { get; set; }
public int RootId { get; set; }
[SqlSugar.SugarColumn(IsIgnore =true)]
public List<ThreeItem2> ThreeItem2 { get; set; }
}
public class TwoItem3
{
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
public int Id { get; set; }
public string Name { get; set; }
public string Desc { get; set; }
}
public class ThreeItem2
{
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
public int Id { get; set; }
public string Name { get; set; }
public string TwoItem2Id { get; set; }
}
public class Country
{
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
public int Id { get; set; }
public string Name { get; set; }
[SqlSugar.SugarColumn(IsIgnore = true)]
public List<Province> Provinces { get; set; }
}
public class Province
{
[SqlSugar.SugarColumn(IsPrimaryKey =true)]
public int Id { get; set; }
public string Name { get; set; }
public int CountryId { get; set; }
[SqlSugar.SugarColumn(IsIgnore = true)]
public List<City> citys { get; set; }
}
public class City
{
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
public int Id { get; set; }
public int ProvinceId { get; set; }
public string Name { get; set; }
}
public class Country1
{
[SqlSugar.SugarColumn(IsPrimaryKey = true,IsIdentity =true)]
public int Id { get; set; }
public string Name { get; set; }
[SqlSugar.SugarColumn(IsIgnore = true)]
public List<Province1> Provinces { get; set; }
}
public class Province1
{
[SqlSugar.SugarColumn(IsPrimaryKey = true,IsIdentity =true)]
public int Id { get; set; }
public string Name { get; set; }
public int CountryId { get; set; }
[SqlSugar.SugarColumn(IsIgnore = true)]
public List<City1> citys { get; set; }
}
public class City1
{
[SqlSugar.SugarColumn(IsPrimaryKey = true,IsIdentity =true)]
public int Id { get; set; }
public int ProvinceId { get; set; }
public string Name { get; set; }
}
}

View File

@ -92,6 +92,7 @@
<Compile Include="Models\MyCustomAttributeTable.cs" />
<Compile Include="Models\Order.cs" />
<Compile Include="Models\OrderItem.cs" />
<Compile Include="Models\SubInsertTest.cs" />
<Compile Include="Models\TestTree.cs" />
<Compile Include="Models\Tree.cs" />
<Compile Include="Models\ViewOrder.cs" />

View File

@ -200,8 +200,16 @@ namespace SqlSugar
{
int id = 0;
if (isIdentity)
{
if (this.Context.CurrentConnectionConfig.DbType == DbType.PostgreSQL)
{
var sqlobj = this.Context.Insertable(insert).AS(tableName).ToSql();
id = this.Context.Ado.GetInt(sqlobj.Key+ " "+ entityInfo.Columns.First(it=>isIdentity).DbColumnName, sqlobj.Value);
}
else
{
id = this.Context.Insertable(insert).AS(tableName).ExecuteReturnIdentity();
}
if (this.Context.CurrentConnectionConfig.DbType == DbType.Oracle&&id==0)
{
var seqName=entityInfo.Columns.First(it => it.OracleSequenceName.HasValue())?.OracleSequenceName;