Bug : ExecuteReturnPkListAsync

This commit is contained in:
sunkaixuan 2022-11-03 09:37:36 +08:00
parent ad08692a6b
commit 113874c6af
4 changed files with 60 additions and 32 deletions

View File

@ -12,31 +12,7 @@ namespace OrmTest
static void Main(string[] args)
{
//Demo
Demo0_SqlSugarClient.Init();
Demo1_Queryable.Init();
Demo2_Updateable.Init();
Demo3_Insertable.Init();
Demo4_Deleteable.Init();
Demo5_SqlQueryable.Init();
DemoN_SplitTable.Init();
Demo6_Queue.Init();
Demo7_Ado.Init();
Demo8_Saveable.Init();
Demo9_EntityMain.Init();
DemoA_DbMain.Init();
DemoB_Aop.Init();
DemoC_GobalFilter.Init();
//DemoD_DbFirst.Init();;
DemoE_CodeFirst.Init();
DemoF_Utilities.Init();
DemoG_SimpleClient.Init();
DemoH_Tenant.Init();
DemoJ_Report.Init();
DemoL_Snowflake.Init();
DemoM_UnitOfWork.Init();
//Unit test
//NewUnitTest.Init();
NewUnitTest.Init();
//Rest Data
NewUnitTest.RestData();

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
namespace OrmTest
{
public partial class NewUnitTest
@ -34,6 +34,54 @@ namespace OrmTest
throw new Exception("unit error");
}
}
var list2=db.Insertable(new List<Order22>() {
new Order22()
{
Name = "a",
CreateTime = DateTime.Now,
CustomId = 1,
Price = 1
},new Order22()
{
Name = "a",
CreateTime = DateTime.Now,
CustomId = 1,
Price = 1
}
}).AS("Order").ExecuteReturnPkList<long>();
var list3 = db.Insertable(new List<Order>() {
new Order ()
{
Name = "a",
CreateTime = DateTime.Now,
CustomId = 1,
Price = 1
},new Order()
{
Name = "a",
CreateTime = DateTime.Now,
CustomId = 1,
Price = 1
}
}).AS("Order").ExecuteReturnPkList<int>();
}
public class Order22
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public long Id { get; set; }
/// <summary>
/// 姓名
/// </summary>
public string Name { get; set; }
public decimal Price { get; set; }
[SugarColumn(IsNullable = true)]
public DateTime CreateTime { get; set; }
[SugarColumn(IsNullable = true)]
public int CustomId { get; set; }
[SugarColumn(IsIgnore = true)]
public List<OrderItem> Items { get; set; }
}
public class Unitsdafa111
{

View File

@ -70,18 +70,17 @@ namespace SqlSugar
RestoreMapping();
return new KeyValuePair<string, List<SugarParameter>>(sql, InsertBuilder.Parameters);
}
public async Task<List<Type>> ExecuteReturnPkListAsync<Type>()
{
return await Task.Run(() => ExecuteReturnPkList<Type>());
}
public virtual List<Type> ExecuteReturnPkList<Type>()
{
var pkInfo= this.EntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
Check.ExceptionEasy(pkInfo==null,"ExecuteReturnPkList need primary key", "ExecuteReturnPkList需要主键");
Check.ExceptionEasy(this.EntityInfo.Columns.Count(it => it.IsPrimarykey == true)>1, "ExecuteReturnPkList Only support technology single primary key", "ExecuteReturnPkList只支技单主键");
var isIdEntity = pkInfo.IsIdentity|| (pkInfo.OracleSequenceName.HasValue()&&this.Context.CurrentConnectionConfig.DbType==DbType.Oracle);
if (pkInfo.UnderType == UtilConstants.LongType)
{
return InsertPkListLong<Type>();
}
else if (isIdEntity&&this.InsertObjs.Length==1)
if (isIdEntity&&this.InsertObjs.Length==1)
{
return InsertPkListIdentityCount1<Type>(pkInfo);
}
@ -93,6 +92,10 @@ namespace SqlSugar
{
return InsertPkListWithFunc<Type>(pkInfo);
}
else if (pkInfo.UnderType == UtilConstants.LongType)
{
return InsertPkListLong<Type>();
}
else
{
return InsertPkListGuid<Type>(pkInfo);

View File

@ -13,6 +13,7 @@ namespace SqlSugar
int ExecuteCommand();
Task<int> ExecuteCommandAsync();
List<Type> ExecuteReturnPkList<Type>();
Task<List<Type>> ExecuteReturnPkListAsync<Type>();
long ExecuteReturnSnowflakeId();
List<long> ExecuteReturnSnowflakeIdList();
Task<long> ExecuteReturnSnowflakeIdAsync();