Browse Source

Update Insertable.UseParameter

pull/6/head
sunkaixuna 3 years ago
parent
commit
32cd9fcd89
  1. 2
      Src/Asp.Net/SqlServerTest/Demo/Demo3_Insertable.cs
  2. 3
      Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs
  3. 21
      Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/ParameterInsertable.cs
  4. 2
      Src/Asp.Net/SqlSugar/Interface/IParameterInsertable.cs

2
Src/Asp.Net/SqlServerTest/Demo/Demo3_Insertable.cs

@ -36,6 +36,8 @@ namespace OrmTest
new Order() { Id = 12, Name = "order12" , Price=0}
};
db.Insertable(insertObjs).RemoveDataCache().IgnoreColumns(it=>it.CreateTime).UseParameter().ExecuteCommand();
//Ignore CreateTime
db.Insertable(insertObj).IgnoreColumns(it => new { it.CreateTime }).ExecuteReturnIdentity();//get identity
db.Insertable(insertObj).IgnoreColumns("CreateTime").ExecuteReturnIdentity();

3
Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs

@ -29,7 +29,7 @@ namespace SqlSugar
public bool IsAs { get; set; }
public bool IsEnableDiffLogEvent { get; set; }
public DiffLogModel diffModel { get; set; }
private Action RemoveCacheFunc { get; set; }
internal Action RemoveCacheFunc { get; set; }
#region Core
@ -229,6 +229,7 @@ namespace SqlSugar
public IParameterInsertable<T> UseParameter()
{
var result = new ParameterInsertable<T>();
result.Context= this.Context;
result.Inserable = this;
return result;
}

21
Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/ParameterInsertable.cs

@ -8,9 +8,28 @@ namespace SqlSugar
{
public class ParameterInsertable<T> : IParameterInsertable<T> where T:class,new()
{
public InsertableProvider<T> Inserable { get; set; }
internal IInsertable<T> Inserable { get; set; }
internal SqlSugarProvider Context { get; set; }
public int ExecuteCommand()
{
int result = 0;
var inserable = Inserable as InsertableProvider<T>;
var columns= inserable.InsertBuilder.DbColumnInfoList.GroupBy(it => it.DbColumnName).Select(it=>it.Key).Distinct().ToList();
var tableWithString = inserable.InsertBuilder.TableWithString;
var removeCacheFunc = inserable.RemoveCacheFunc;
var objects = inserable.InsertObjs;
this.Context.Utilities.PageEach(objects, 60, pagelist =>
{
foreach (var item in pagelist)
{
var itemable = this.Context.Insertable(item);
itemable.InsertBuilder.DbColumnInfoList = itemable.InsertBuilder.DbColumnInfoList.Where(it => columns.Contains(it.DbColumnName)).ToList();
itemable.InsertBuilder.TableWithString = tableWithString;
(itemable as InsertableProvider<T>).RemoveCacheFunc = removeCacheFunc;
itemable.AddQueue();
}
result+=this.Context.SaveQueues(false);
});
return 0;
}
}

2
Src/Asp.Net/SqlSugar/Interface/IParameterInsertable.cs

@ -2,6 +2,6 @@
{
public interface IParameterInsertable<T>
{
InsertableProvider<T> Inserable { get; set; }
int ExecuteCommand();
}
}
Loading…
Cancel
Save