SqlSugar/Src/Asp.Net/MySqlTest/UnitTest/UInsert.cs

99 lines
2.2 KiB
C#
Raw Normal View History

2021-02-04 15:54:42 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
public partial class NewUnitTest
{
public class Unit4ASDF
{
2021-03-27 14:46:31 +08:00
[SqlSugar.SugarColumn(ColumnDataType = " bigint(20)", IsNullable = true)]
2021-02-04 15:54:42 +08:00
public long? Id { get; set; }
2021-03-27 14:46:31 +08:00
[SqlSugar.SugarColumn(ColumnDataType = " bigint(20)")]
2021-02-04 15:54:42 +08:00
public long Id2 { get; set; }
}
public static void Insert()
{
Db.CodeFirst.InitTables<Unit4ASDF>();
Db.Insertable(new List<Unit4ASDF>() {
new Unit4ASDF() { Id=null, Id2=1 },
2021-08-07 03:16:18 +08:00
new Unit4ASDF() { Id=2, Id2=1 }}).UseMySql().ExecuteBlukCopy();
2021-02-04 15:54:42 +08:00
var list = Db.Queryable<Unit4ASDF>().ToList();
2021-03-27 14:30:23 +08:00
Db.CodeFirst.InitTables<testdb>();
Db.DbMaintenance.TruncateTable("testdb");
var list1 = new List<testdb>();
for (int i = 0; i < 10; i++)
{
var id = i.ToString();
list1.Add(new testdb
{
id = id,
});
Console.WriteLine(id + " Length" + id.Length);
}
2021-08-07 03:16:18 +08:00
Db.Insertable(list1).UseMySql().ExecuteBlukCopy();
2021-03-27 14:30:23 +08:00
var queryList = Db.Queryable<testdb>().ToList();
foreach (var item in queryList)
{
if (item.id.Length != 1)
{
throw new Exception("blue copy");
}
}
2021-03-27 14:46:31 +08:00
Db.CodeFirst.InitTables<Testdbbool>();
Db.DbMaintenance.TruncateTable("Testdbbool");
2021-08-07 03:16:18 +08:00
Db.Insertable(new Testdbbool() { isok=true }).UseMySql().ExecuteBlukCopy();
Db.Insertable(new Testdbbool() { isok = false }).UseMySql().ExecuteBlukCopy();
2021-03-27 14:46:31 +08:00
var x=Db.Queryable<Testdbbool>().ToList();
2021-03-27 14:30:23 +08:00
}
public class testdb
{
public string id { get; set; }
2021-02-04 15:54:42 +08:00
}
2021-03-27 14:46:31 +08:00
public class Testdbbool
{
[SqlSugar.SugarColumn(IsPrimaryKey = true,IsIdentity =true)]
public int id { get; set; }
public bool isok { get; set; }
}
2021-02-04 15:54:42 +08:00
}
}