You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
213 lines
24 KiB
213 lines
24 KiB
3 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
|
||
|
namespace OrmTest
|
||
|
{
|
||
|
public partial class NewUnitTest
|
||
|
{
|
||
|
public static string bulkData1 = @"{""data"":[{""id"":0,""robot_wx_id"":""wxid_0p3bww1ouyvi12"",""robot_serial_no"":""3927EE296470127DD1F1DF6274467A7A"",""device_user_serial_no"":""F27C2578D8004E9F8644EBC023C0A582"",""wx_account"":""lvqiujingliu1986"",""wx_password"":""8836MjQ2MWFhYWEyMzQ5"",""wx_alias"":""lvqiujingliu1986"",""nick_name"":""闾丘睛六"",""base64_nick_name"":""6Ze+5LiY552b5YWt"",""headimg_url"":""https://wx.qlogo.cn/mmhead/ver_1/VlhejJkdGe5YhcXdIVHYibxKbntVE85ZiayxtN2NnSibSViapXLEPY2mt1kHrZbqXnfgenBnNrp8Cx95YN1Uxic2E7Gzdfk2DSnYeUuR2QVpQJ28/132"",""email"":"""",""sex"":0,""enabled"":true,""type"":10,""status"":10,""seal_status"":10,""protocol_type"":2,""city_no"":"""",""province_no"":"""",""separation"":false,""parent_id"":0,""uin"":""1541723256"",""update_time"":""2022-01-12T09:57:13.377"",""create_time"":""2021-12-24T16:08:20.84"",""remark"":""机器人信息·数据初始化""},{""id"":0,""robot_wx_id"":""wxid_ln20qwymng8422"",""robot_serial_no"":""39289F28EAD96B4474A608919011FDEB"",""device_user_serial_no"":""20200917101004889010110000391"",""wx_account"":""ik50u73"",""wx_password"":""3uvhM3V2aDN1dmg2Z3Fl"",""wx_alias"":""ik50u73"",""nick_name"":""缪茹茹"",""base64_nick_name"":""57yq6Iy56Iy5"",""headimg_url"":""https://wx.qlogo.cn/mmhead/ver_1/Q7gjPhRR5ahEIP3DWyzIVvj1dPkGRTXia4hBTEY4VBCjq45jBkXc2A4ZwjWGhgKZ8AWDWt6LZpL3qic5dN2t5H5Nz1BI3iaqWlqBpZYticftusE/132"",""email"":"""",""sex"":2,""enabled"":true,""type"":10,""status"":10,""seal_status"":10,""protocol_type"":2,""city_no"":"""",""province_no"":"""",""separation"":false,""parent_id"":0,""uin"":""2342964524"",""update_time"":""2022-01-11T19:26:38.86"",""create_time"":""2020-07-08T14:26:57.907"",""remark"":""机器人信息·数据初始化""},{""id"":0,""robot_wx_id"":""wxid_0prnyg6n7aat22"",""robot_serial_no"":""39281E97D2F28A1BA848EED509D1D914"",""device_user_serial_no"":""20220105175222407210210002286"",""wx_account"":"""",""wx_password"":"""",""wx_alias"":"""",""nick_name"":""烈文"",""base64_nick_name"":""54OI5paH"",""headimg_url"":""https://wx.qlogo.cn/mmhead/ver_1/3S5EfQYud7JQ9bibib2sUHSE18HskHNF4yE6DrgvjRbBWawfreZlR6KR0ZhE5MrFWWv6b4JLHQdUUlWicqnWWvhgtdLpAlicURuHeD0k6qvX7dE/132"",""email"":"""",""sex"":2,""enabled"":true,""type"":30,""status"":10,""seal_status"":10,""protocol_type"":1,""city_no"":"""",""province_no"":"""",""separation"":false,""parent_id"":0,""uin"":""2483638563"",""update_time"":""2022-01-11T17:55:05.147"",""create_time"":""2021-10-15T13:30:50.637"",""remark"":""机器人信息·数据初始化""},{""id"":0,""robot_wx_id"":""wxid_rbhtxkd819ug21"",""robot_serial_no"":""3928E3EF41E241987190AAD5CD3896FA"",""device_user_serial_no"":""20211129100847022010210001354"",""wx_account"":"""",""wx_password"":"""",""wx_alias"":""jammy__C"",""nick_name"":""婕"",""base64_nick_name"":""5amV"",""headimg_url"":""https://wx.qlogo.cn/mmhead/ver_1/CB1XmYSqgFJ9no4HR6icKgnf8uJKGX8BQUqhsR9CoyFpqh3QxJCWMmGkslicXyVjiaCZyBjC9DL7eXBicOKnbe9kun5yW8cBlqSDhR0vIjGaOuQ/132"",""email"":"""",""sex"":2,""enabled"":true,""type"":30,""status"":10,""seal_status"":10,""protocol_type"":1,""city_no"":"""",""province_no"":"""",""separation"":false,""parent_id"":0,""uin"":""1083130244"",""update_time"":""2022-01-10T13:06:27.823"",""create_time"":""2021-09-27T11:33:16.327"",""remark"":""机器人信息·数据初始化""},{""id"":0,""robot_wx_id"":""wxid_opxbbhmzlakx12"",""robot_serial_no"":""392734726B89AFD98BD54F87A6F7A323"",""device_user_serial_no"":""C64EA13FFEDE4AC587E3E189CC32ED2B"",""wx_account"":""lugao1106"",""wx_password"":""9591Y2UxYnd3d3cxNTQ5"",""wx_alias"":""lugao1106"",""nick_name"":""逯缟"",""base64_nick_name"":""6YCv57yf"",""headimg_url"":""https://wx.qlogo.cn/mmhead/ver_1/6O6v8T7HbFiag6MJTQErfNdoNhG08wQx4rXApdQfjdcnxEZFcjlOmB1mFJ4OfBYhkvhibUzdCegsY0YiaYtwpEtpg/132"",""email"":"""",""sex"":0,""enabled"":true,""type"":10,""status"":10,""seal_status"":10,""protocol_type"":2,""city_no"":"""",""province_no"":"""",""separation"":false,""parent_id"":0,""uin"":""202535294"",""update_time"":""2022-01-11T11:18:08.897"",""create_time"":""2021-11-
|
||
|
|
||
|
public static void Bulk()
|
||
|
{
|
||
|
Db.CodeFirst.InitTables<UnitIdentity1>();
|
||
|
Db.DbMaintenance.TruncateTable<UnitIdentity1>();
|
||
|
var data = new UnitIdentity1()
|
||
|
{
|
||
|
Name = "jack"
|
||
|
};
|
||
|
Db.Fastest<UnitIdentity1>().BulkCopy(new List<UnitIdentity1>() {
|
||
|
data
|
||
|
});
|
||
|
var list = Db.Queryable<UnitIdentity1>().ToList();
|
||
|
if (list.Count != 1 || data.Name != list.First().Name)
|
||
|
{
|
||
|
throw new Exception("unit Bulk");
|
||
|
}
|
||
|
data.Name = "2";
|
||
|
Db.Fastest<UnitIdentity1>().BulkCopy(new List<UnitIdentity1>() {
|
||
|
data,
|
||
|
data
|
||
|
});
|
||
|
list = Db.Queryable<UnitIdentity1>().ToList();
|
||
|
if (list.Count != 3 || !list.Any(it => it.Name == "2"))
|
||
|
{
|
||
|
throw new Exception("unit Bulk");
|
||
|
}
|
||
|
Db.Fastest<UnitIdentity1>().BulkUpdate(new List<UnitIdentity1>() {
|
||
|
new UnitIdentity1(){
|
||
|
Id=1,
|
||
|
Name="222"
|
||
|
},
|
||
|
new UnitIdentity1(){
|
||
|
Id=2,
|
||
|
Name="111"
|
||
|
}
|
||
|
});
|
||
|
list = Db.Queryable<UnitIdentity1>().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<UnitIdentity111>();
|
||
|
Db.DbMaintenance.TruncateTable<UnitIdentity111>();
|
||
|
var count = Db.Fastest<UnitIdentity111111111>().AS("UnitIdentity111").BulkCopy(new List<UnitIdentity111111111> {
|
||
|
new UnitIdentity111111111(){ Id=1, Name="jack" }
|
||
|
});
|
||
|
if (count == 0)
|
||
|
{
|
||
|
throw new Exception("unit Bulk");
|
||
|
}
|
||
|
count = Db.Fastest<UnitIdentity111111111>().AS("UnitIdentity111").BulkUpdate(new List<UnitIdentity111111111> {
|
||
|
new UnitIdentity111111111(){ Id=1, Name="jack" }
|
||
|
});
|
||
|
if (count == 0)
|
||
|
{
|
||
|
throw new Exception("unit Bulk");
|
||
|
}
|
||
|
Db.CodeFirst.InitTables<UnitTable001>();
|
||
|
Db.Fastest<UnitTable001>().BulkUpdate(new List<UnitTable001> {
|
||
|
new UnitTable001(){ Id=1, table="a" }
|
||
|
});
|
||
|
|
||
|
Db.CodeFirst.InitTables<UnitBulk23131>();
|
||
|
Db.DbMaintenance.TruncateTable<UnitBulk23131>();
|
||
|
Db.Fastest<UnitBulk23131>().BulkCopy(new List<UnitBulk23131> {
|
||
|
new UnitBulk23131()
|
||
|
{
|
||
|
Id = 1,
|
||
|
table = false
|
||
|
}
|
||
|
});
|
||
|
var list1 = Db.Queryable<UnitBulk23131>().ToList();
|
||
|
SqlSugar.Check.Exception(list1.First().table == true, "unit error");
|
||
|
Db.Fastest<UnitBulk23131>().BulkUpdate(new List<UnitBulk23131> {
|
||
|
new UnitBulk23131()
|
||
|
{
|
||
|
Id = 1,
|
||
|
table = true
|
||
|
}
|
||
|
});
|
||
|
var list2 = Db.Queryable<UnitBulk23131>().ToList();
|
||
|
SqlSugar.Check.Exception(list2.First().table == false, "unit error");
|
||
|
|
||
|
Db.DbMaintenance.TruncateTable<UnitBulk23131>();
|
||
|
Db.Fastest<UnitBulk23131>().BulkCopy(new List<UnitBulk23131> {
|
||
|
new UnitBulk23131()
|
||
|
{
|
||
|
Id = 1,
|
||
|
table = true
|
||
|
}
|
||
|
});
|
||
|
var list3 = Db.Queryable<UnitBulk23131>().ToList();
|
||
|
SqlSugar.Check.Exception(list3.First().table == false, "unit error");
|
||
|
Db.Fastest<UnitBulk23131>().BulkUpdate(new List<UnitBulk23131> {
|
||
|
new UnitBulk23131()
|
||
|
{
|
||
|
Id = 1,
|
||
|
table = false
|
||
|
}
|
||
|
});
|
||
|
list3 = Db.Queryable<UnitBulk23131>().ToList();
|
||
|
SqlSugar.Check.Exception(list3.First().table == true, "unit error");
|
||
|
|
||
|
Db.DbMaintenance.TruncateTable<UnitBulk23131>();
|
||
|
Db.Fastest<UnitBulk23131>().BulkCopy(new List<UnitBulk23131> {
|
||
|
new UnitBulk23131()
|
||
|
{
|
||
|
Id = 1,
|
||
|
table = null
|
||
|
}
|
||
|
});
|
||
|
var list4 = Db.Queryable<UnitBulk23131>().ToList();
|
||
|
SqlSugar.Check.Exception(list4.First().table == true, "unit error");
|
||
|
|
||
|
Db.CodeFirst.InitTables<UnitBulkCopy1231>();
|
||
|
Db.CodeFirst.InitTables<UnitDatum>();
|
||
|
var rootData=Db.Utilities.DeserializeObject<Rootobject>(bulkData1);
|
||
|
var inserData = rootData.data.ToList();
|
||
|
var num= Db.Fastest<UnitDatum>().BulkCopy(inserData);
|
||
|
SqlSugar.Check.Exception(num != 20, "unit error");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public class Rootobject
|
||
|
{
|
||
|
public UnitDatum[] data { get; set; }
|
||
|
}
|
||
|
|
||
|
public class UnitDatum
|
||
|
{
|
||
|
public int id { get; set; }
|
||
|
public string robot_wx_id { get; set; }
|
||
|
public string robot_serial_no { get; set; }
|
||
|
public string device_user_serial_no { get; set; }
|
||
|
public string wx_account { get; set; }
|
||
|
public string wx_password { get; set; }
|
||
|
public string wx_alias { get; set; }
|
||
|
public string nick_name { get; set; }
|
||
|
public string base64_nick_name { get; set; }
|
||
|
public string headimg_url { get; set; }
|
||
|
public string email { get; set; }
|
||
|
public int sex { get; set; }
|
||
|
public bool enabled { get; set; }
|
||
|
public int type { get; set; }
|
||
|
public int status { get; set; }
|
||
|
public int seal_status { get; set; }
|
||
|
public int protocol_type { get; set; }
|
||
|
public string city_no { get; set; }
|
||
|
public string province_no { get; set; }
|
||
|
public bool separation { get; set; }
|
||
|
public int parent_id { get; set; }
|
||
|
public string uin { get; set; }
|
||
|
public DateTime update_time { get; set; }
|
||
|
public DateTime create_time { get; set; }
|
||
|
public string remark { get; set; }
|
||
|
}
|
||
|
|
||
|
public class UnitBulkCopy1231
|
||
|
{
|
||
|
public string Id { get; set; }
|
||
|
}
|
||
|
public class UnitBulk23131
|
||
|
{
|
||
|
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
|
||
|
public int Id { get; set; }
|
||
|
[SqlSugar.SugarColumn(ColumnDataType = "tinyint", Length = 1, IsNullable = true)]
|
||
|
public bool? table { get; set; }
|
||
|
}
|
||
|
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; }
|
||
|
}
|
||
|
}
|