using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace OrmTest { public partial class NewUnitTest { public static void Bulk() { Db.CodeFirst.InitTables(); Db.DbMaintenance.TruncateTable(); var data = new UnitIdentity1() { Name = "jack" }; Db.Fastest().BulkCopy(new List() { data }); var list=Db.Queryable().ToList(); if (list.Count != 1 || data.Name != list.First().Name) { throw new Exception("unit Bulk"); } data.Name = "2"; Db.Fastest().BulkCopy(new List() { data, data }); list = Db.Queryable().ToList(); if (list.Count != 3 || !list.Any(it=>it.Name=="2")) { throw new Exception("unit Bulk"); } Db.Fastest().BulkUpdate(new List() { new UnitIdentity1(){ Id=1, Name="222" }, new UnitIdentity1(){ Id=2, Name="111" } }); list = Db.Queryable().ToList(); if (list.First(it=>it.Id==1).Name!="222") { throw new Exception("unit Bulk"); } if (list.First(it => it.Id == 2).Name != "111") { throw new Exception("unit Bulk"); } if (list.First(it => it.Id == 3).Name != "2") { throw new Exception("unit Bulk"); } Db.CodeFirst.InitTables(); Db.DbMaintenance.TruncateTable(); var count=Db.Fastest().AS("UnitIdentity111").BulkCopy(new List { new UnitIdentity111111111(){ Id=1, Name="jack" } }); if (count == 0) { throw new Exception("unit Bulk"); } count = Db.Fastest().AS("UnitIdentity111").BulkUpdate(new List { new UnitIdentity111111111(){ Id=1, Name="jack" } }); if (count == 0) { throw new Exception("unit Bulk"); } Db.CodeFirst.InitTables(); Db.Fastest().BulkUpdate(new List { new UnitTable001(){ Id=1, table="a" } }); } } public class UnitTable001 { [SqlSugar.SugarColumn(IsPrimaryKey =true)] public int Id { get; set; } public string table { get; set; } } public class UnitIdentity111 { public int Id { get; set; } public string Name { get; set; } } public class UnitIdentity111111111 { [SqlSugar.SugarColumn(IsPrimaryKey = true)] public int Id { get; set; } public string Name { get; set; } } public class UnitIdentity1 { [SqlSugar.SugarColumn(IsPrimaryKey =true,IsIdentity =true)] public int Id { get; set; } public string Name { get; set; } } }