Browse Source

Update db.Storageable

pull/2/head
skx 4 years ago
parent
commit
50728c26dc
  1. 4
      Src/Asp.Net/SqlServerTest/UnitTest/UInsert.cs
  2. 21
      Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/IStorageable.cs
  3. 8
      Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs
  4. 18
      Src/Asp.Net/SqlSugar/Interface/IStorageable.cs

4
Src/Asp.Net/SqlServerTest/UnitTest/UInsert.cs

@ -65,8 +65,8 @@ namespace OrmTest
list2.First().Name = null;
db.DbMaintenance.TruncateTable<UinitBlukTable>();
var x=Db.Storageable(list2)
.SplitInsert(it => !string.IsNullOrEmpty(it.Item.Name))
.SplitUpdate(it => string.IsNullOrEmpty(it.Item.Name))
//.SplitInsert(it => !string.IsNullOrEmpty(it.Item.Name))
//.SplitUpdate(it => string.IsNullOrEmpty(it.Item.Name))
.SplitDelete(it=>it.Item.Id>10)
.SplitIgnore(it=>it.Item.Id==2)
.SplitError(it => it.Item.Id == 3,"id不能等于3")

21
Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/IStorageable.cs

@ -62,10 +62,13 @@ namespace SqlSugar
{
if (this.datas.Count == 0)
return new StorageableResult<T>();
var messageList = datas.Select(it => new StorageableMessage<T>() {
Item=it.Item
}).ToList();
foreach (var item in whereFuncs.OrderByDescending(it => (int)it.key))
{
List<StorageableInfo<T>> whereList = datas.Where(it => it.StorageType == null).ToList();
Func<StorageableInfo<T>, bool> exp = item.value1;
List<StorageableMessage<T>> whereList = messageList.Where(it => it.StorageType == null).ToList();
Func<StorageableMessage<T>, bool> exp = item.value1;
var list = whereList.Where(exp).ToList();
foreach (var it in list)
{
@ -73,12 +76,12 @@ namespace SqlSugar
it.StorageMessage = item.value2;
}
}
var delete = datas.Where(it => it.StorageType == StorageType.Delete).ToList();
var update = datas.Where(it => it.StorageType == StorageType.Update).ToList();
var inset = datas.Where(it => it.StorageType == StorageType.Insert).ToList();
var error = datas.Where(it => it.StorageType == StorageType.Error).ToList();
var ignore = datas.Where(it => it.StorageType == StorageType.Ignore||it.StorageType==null).ToList();
var other = datas.Where(it => it.StorageType == StorageType.Other).ToList();
var delete = messageList.Where(it => it.StorageType == StorageType.Delete).ToList();
var update = messageList.Where(it => it.StorageType == StorageType.Update).ToList();
var inset = messageList.Where(it => it.StorageType == StorageType.Insert).ToList();
var error = messageList.Where(it => it.StorageType == StorageType.Error).ToList();
var ignore = messageList.Where(it => it.StorageType == StorageType.Ignore||it.StorageType==null).ToList();
var other = messageList.Where(it => it.StorageType == StorageType.Other).ToList();
StorageableResult<T> result = new StorageableResult<T>()
{
AsDeleteable = this.Context.Deleteable(delete.Select(it => it.Item).ToList()),
@ -90,7 +93,7 @@ namespace SqlSugar
UpdateList = update,
ErrorList = error,
IgnoreList = ignore,
TotalList = datas
TotalList = messageList
};
return result;
}

8
Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs

@ -53,6 +53,10 @@ namespace SqlSugar
public virtual int ExecuteCommand()
{
string sql = _ExecuteCommand();
if (string.IsNullOrEmpty(sql))
{
return 0;
}
var result = this.Ado.ExecuteCommand(sql, UpdateBuilder.Parameters == null ? null : UpdateBuilder.Parameters.ToArray());
After(sql);
return result;
@ -64,6 +68,10 @@ namespace SqlSugar
public async Task<int> ExecuteCommandAsync()
{
string sql = _ExecuteCommand();
if (string.IsNullOrEmpty(sql))
{
return 0;
}
var result = await this.Ado.ExecuteCommandAsync(sql, UpdateBuilder.Parameters == null ? null : UpdateBuilder.Parameters.ToArray());
After(sql);
return result;

18
Src/Asp.Net/SqlSugar/Interface/IStorageable.cs

@ -22,6 +22,10 @@ namespace SqlSugar
{
public T Item { get; set; }
public List<T> ExistData { get; set; }
}
public class StorageableMessage<T> : StorageableInfo<T> where T : class, new()
{
public string StorageMessage { get; set; }
public StorageType? StorageType { get; set; }
}
@ -50,13 +54,13 @@ namespace SqlSugar
public class StorageableResult<T> where T : class, new()
{
public List<StorageableInfo<T>> TotalList { get; set; }
public List<StorageableInfo<T>> InsertList { get; set; }
public List<StorageableInfo<T>> UpdateList { get; set; }
public List<StorageableInfo<T>> DeleteList { get; set; }
public List<StorageableInfo<T>> ErrorList { get; set; }
public List<StorageableInfo<T>> IgnoreList { get; set; }
public List<StorageableInfo<T>> OtherList { get; set; }
public List<StorageableMessage<T>> TotalList { get; set; }
public List<StorageableMessage<T>> InsertList { get; set; }
public List<StorageableMessage<T>> UpdateList { get; set; }
public List<StorageableMessage<T>> DeleteList { get; set; }
public List<StorageableMessage<T>> ErrorList { get; set; }
public List<StorageableMessage<T>> IgnoreList { get; set; }
public List<StorageableMessage<T>> OtherList { get; set; }
public IInsertable<T> AsInsertable { get; set; }
public IUpdateable<T> AsUpdateable { get; set; }
public IDeleteable<T> AsDeleteable { get; set; }

Loading…
Cancel
Save