mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 13:06:50 +08:00
Storageable BUG
This commit is contained in:
parent
00c05aa393
commit
7ccee2cc9e
@ -143,6 +143,10 @@ namespace SqlSugar
|
||||
{
|
||||
parameterName = parameterName.Replace("]", "_");
|
||||
}
|
||||
if (parameterName.Contains(this.SqlTranslationLeft))
|
||||
{
|
||||
parameterName = parameterName.Replace(this.SqlTranslationLeft, "_");
|
||||
}
|
||||
switch (item.ConditionalType)
|
||||
{
|
||||
case ConditionalType.Equal:
|
||||
|
@ -117,6 +117,7 @@ namespace SqlSugar
|
||||
|
||||
#region Saveable
|
||||
IStorageable<T> Storageable<T>(List<T> dataList) where T : class, new();
|
||||
IStorageable<T> Storageable<T>(T data) where T : class, new();
|
||||
ISaveable<T> Saveable<T>(List<T> saveObjects) where T : class, new();
|
||||
ISaveable<T> Saveable<T>(T saveObject) where T : class, new();
|
||||
#endregion
|
||||
|
@ -343,6 +343,10 @@ namespace SqlSugar
|
||||
{
|
||||
return this.Context.Storageable(dataList);
|
||||
}
|
||||
public IStorageable<T> Storageable<T>(T data) where T : class, new()
|
||||
{
|
||||
return this.Context.Storageable(new List<T> { data});
|
||||
}
|
||||
public ISaveable<T> Saveable<T>(List<T> saveObjects) where T : class, new()
|
||||
{
|
||||
return this.Context.Saveable<T>(saveObjects);
|
||||
|
@ -81,6 +81,7 @@
|
||||
<Compile Include="UnitTest\Main.cs" />
|
||||
<Compile Include="UnitTest\UAdo.cs" />
|
||||
<Compile Include="UnitTest\UCodeFirst.cs" />
|
||||
<Compile Include="UnitTest\UInsert.cs" />
|
||||
<Compile Include="UnitTest\UJson.cs" />
|
||||
<Compile Include="UnitTest\Updateable.cs" />
|
||||
<Compile Include="UnitTest\UQueryable.cs" />
|
||||
|
@ -31,15 +31,16 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
Insert();
|
||||
CodeFirst();
|
||||
Updateable();
|
||||
Json();
|
||||
Ado();
|
||||
Queryable();
|
||||
QueryableAsync();
|
||||
Thread();
|
||||
Thread2();
|
||||
Thread3();
|
||||
//Thread();
|
||||
//Thread2();
|
||||
//Thread3();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
198
Src/Asp.Net/SqliteTest/UnitTest/UInsert.cs
Normal file
198
Src/Asp.Net/SqliteTest/UnitTest/UInsert.cs
Normal file
@ -0,0 +1,198 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public partial class NewUnitTest
|
||||
{
|
||||
public static void Insert()
|
||||
{
|
||||
var db = Db;
|
||||
|
||||
db.CodeFirst.InitTables<UinitBlukTable>();
|
||||
var list = db.Queryable<UinitBlukTable>().ToList();
|
||||
db.DbMaintenance.TruncateTable<UinitBlukTable>();
|
||||
|
||||
List<UinitBlukTable> list2 = new List<UinitBlukTable>();
|
||||
for (int i = 1; i <= 20; i++)
|
||||
{
|
||||
UinitBlukTable data = new UinitBlukTable()
|
||||
{
|
||||
Create=DateTime.Now.AddDays(-1),
|
||||
Id=i ,
|
||||
Name =i%3==0?"a":"b"
|
||||
};
|
||||
list2.Add(data);
|
||||
}
|
||||
list2.First().Name = null;
|
||||
db.DbMaintenance.TruncateTable<UinitBlukTable>();
|
||||
db.Insertable(new UinitBlukTable() { Id = 2, Name = "b", Create = DateTime.Now }).ExecuteCommand();
|
||||
var x=Db.Storageable(list2)
|
||||
.SplitInsert(it => it.NotAny(y=>y.Id==it.Item.Id))
|
||||
.SplitUpdate(it => it.Any(y => y.Id == it.Item.Id))
|
||||
.SplitDelete(it=>it.Item.Id>10)
|
||||
.SplitIgnore(it=>it.Item.Id==1)
|
||||
.SplitError(it => it.Item.Id == 3,"id不能等于3")
|
||||
.SplitError(it => it.Item.Id == 4, "id不能等于4")
|
||||
.SplitError(it => it.Item.Id == 5, "id不能等于5")
|
||||
.SplitError(it => it.Item.Name==null, "name不能等于")
|
||||
.WhereColumns(it=> new { it.Id })
|
||||
.ToStorage();
|
||||
x.AsDeleteable.ExecuteCommand();
|
||||
x.AsInsertable.ExecuteCommand();
|
||||
x.AsUpdateable.ExecuteCommand();
|
||||
foreach (var item in x.ErrorList)
|
||||
{
|
||||
Console.Write(item.StorageMessage+" ");
|
||||
}
|
||||
db.DbMaintenance.TruncateTable<UinitBlukTable>();
|
||||
IDemo1();
|
||||
IDemo2();
|
||||
IDemo3();
|
||||
IDemo4();
|
||||
}
|
||||
private static void IDemo4()
|
||||
{
|
||||
var db = Db;
|
||||
db.DbMaintenance.TruncateTable<UinitBlukTable>();
|
||||
|
||||
List<UinitBlukTable> list2 = new List<UinitBlukTable>();
|
||||
list2.Add(new UinitBlukTable() { Id = 1, Name = "a", Create = DateTime.Now });
|
||||
list2.Add(new UinitBlukTable() { Id = 2, Name = "a", Create = DateTime.Now });
|
||||
list2.Add(new UinitBlukTable() { Id = 3, Name = "a", Create = DateTime.Now.AddYears(-2) });
|
||||
list2.Add(new UinitBlukTable() { Id = 4, Name ="", Create = DateTime.Now.AddYears(-2) });
|
||||
|
||||
db.Insertable(list2.First()).ExecuteCommand();//插入第一条
|
||||
|
||||
var x = Db.Storageable(list2)
|
||||
.SplitError(it => string.IsNullOrEmpty(it.Item.Name), "名称不能为空")
|
||||
.SplitError(it => it.Item.Create<DateTime.Now.AddYears(-1),"不是今年的数据")
|
||||
.SplitUpdate(it => it.Any(y=>y.Id==it.Item.Id))//存在更新
|
||||
.SplitInsert(it => true)//剩余的插入
|
||||
.ToStorage();
|
||||
Console.WriteLine(" 插入 {0} 更新{1} 错误数据{2} 不计算数据{3} 删除数据{4},总共{5}" ,
|
||||
x.InsertList.Count,
|
||||
x.UpdateList.Count,
|
||||
x.ErrorList.Count,
|
||||
x.IgnoreList.Count,
|
||||
x.DeleteList.Count,
|
||||
x.TotalList.Count
|
||||
);
|
||||
foreach (var item in x.ErrorList)
|
||||
{
|
||||
Console.WriteLine("id等于"+item.Item.Id+" : "+item.StorageMessage);
|
||||
}
|
||||
|
||||
int i=x.AsInsertable.ExecuteCommand();
|
||||
Console.WriteLine(1 + "条成功插入");
|
||||
i=x.AsUpdateable.ExecuteCommand();
|
||||
Console.WriteLine(1 + "条成功更新");
|
||||
|
||||
db.DbMaintenance.TruncateTable<UinitBlukTable>();
|
||||
}
|
||||
private static void IDemo3()
|
||||
{
|
||||
var db = Db;
|
||||
db.DbMaintenance.TruncateTable<UinitBlukTable>();
|
||||
List<UinitBlukTable> list2 = new List<UinitBlukTable>();
|
||||
list2.Add(new UinitBlukTable() { Id = 1, Name = "a", Create = DateTime.Now });
|
||||
list2.Add(new UinitBlukTable() { Id = 2, Name = "a", Create = DateTime.Now });
|
||||
list2.Add(new UinitBlukTable() { Id = 3, Name = "a", Create = DateTime.Now });
|
||||
|
||||
var x = Db.Storageable(list2)
|
||||
.SplitUpdate(it => it.Item.Id == 1)
|
||||
.SplitInsert(it => it.Item.Id == 2)
|
||||
.SplitDelete(it => it.Item.Id == 3).ToStorage();
|
||||
|
||||
x.AsInsertable.ExecuteCommand();
|
||||
x.AsUpdateable.ExecuteCommand();
|
||||
x.AsDeleteable.ExecuteCommand();
|
||||
|
||||
if (x.InsertList.Count != 1)
|
||||
{
|
||||
throw new Exception("Unit Insert");
|
||||
}
|
||||
if (x.UpdateList.Count != 1)
|
||||
{
|
||||
throw new Exception("Unit Insert");
|
||||
}
|
||||
if (x.DeleteList.Count != 1)
|
||||
{
|
||||
throw new Exception("Unit Insert");
|
||||
}
|
||||
db.DbMaintenance.TruncateTable<UinitBlukTable>();
|
||||
}
|
||||
|
||||
private static void IDemo1()
|
||||
{
|
||||
var db = Db;
|
||||
db.DbMaintenance.TruncateTable<UinitBlukTable>();
|
||||
List<UinitBlukTable> list2 = new List<UinitBlukTable>();
|
||||
list2.Add(new UinitBlukTable() { Id = 1, Name = "a", Create = DateTime.Now });
|
||||
list2.Add(new UinitBlukTable() { Id = 2, Name = "a", Create = DateTime.Now });
|
||||
list2.Add(new UinitBlukTable() { Id = 0, Name = "a", Create = DateTime.Now });
|
||||
|
||||
var x = Db.Storageable(list2)
|
||||
.SplitUpdate(it => it.Item.Id > 0)
|
||||
.SplitInsert(it => it.Item.Id == 0).ToStorage();
|
||||
x.AsInsertable.ExecuteCommand();
|
||||
x.AsUpdateable.ExecuteCommand();
|
||||
|
||||
if (x.InsertList.Count > 1)
|
||||
{
|
||||
throw new Exception("Unit Insert");
|
||||
}
|
||||
if (x.UpdateList.Count !=2)
|
||||
{
|
||||
throw new Exception("Unit Insert");
|
||||
}
|
||||
db.DbMaintenance.TruncateTable<UinitBlukTable>();
|
||||
}
|
||||
private static void IDemo2()
|
||||
{
|
||||
var db = Db;
|
||||
db.DbMaintenance.TruncateTable<UinitBlukTable>();
|
||||
List<UinitBlukTable> list2 = new List<UinitBlukTable>();
|
||||
list2.Add(new UinitBlukTable() { Id = 1, Name = "a1", Create = DateTime.Now });
|
||||
list2.Add(new UinitBlukTable() { Id = 2, Name = "a2", Create = DateTime.Now });
|
||||
list2.Add(new UinitBlukTable() { Id = 3, Name = "a3", Create = DateTime.Now });
|
||||
db.Insertable(list2[1]).ExecuteCommand();
|
||||
|
||||
var x = Db.Storageable(list2)
|
||||
.SplitUpdate(it => it.Any(y=>y.Id==it.Item.Id))
|
||||
.SplitInsert(it => it.NotAny(y => y.Id == it.Item.Id)).ToStorage();
|
||||
x.AsInsertable.ExecuteCommand();
|
||||
x.AsUpdateable.ExecuteCommand();
|
||||
|
||||
|
||||
if (x.InsertList.Count!=2)
|
||||
{
|
||||
throw new Exception("Unit Insert");
|
||||
}
|
||||
if (x.UpdateList.Count != 1)
|
||||
{
|
||||
throw new Exception("Unit Insert");
|
||||
}
|
||||
db.DbMaintenance.TruncateTable<UinitBlukTable>();
|
||||
}
|
||||
|
||||
public class UinitBlukTable
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey =true)]
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
[SqlSugar.SugarColumn(IsNullable =true)]
|
||||
public DateTime? Create { get; set; }
|
||||
}
|
||||
[SqlSugar.SugarTable("UinitBlukTable")]
|
||||
public class UinitBlukTable2
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user