mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 13:06:50 +08:00
Update Core
This commit is contained in:
parent
56c953ca70
commit
bfa9a14748
@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
|||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
namespace OrmTest
|
namespace OrmTest
|
||||||
{
|
{
|
||||||
public class Demo1_SqlSugarClient
|
public class Demo0_SqlSugarClient
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void Init()
|
public static void Init()
|
||||||
@ -35,12 +35,21 @@ namespace OrmTest
|
|||||||
OnLogExecuting = (sql, p) =>
|
OnLogExecuting = (sql, p) =>
|
||||||
{
|
{
|
||||||
Console.WriteLine(sql);
|
Console.WriteLine(sql);
|
||||||
|
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//if no exist create datebase SQLSUGAR4XTEST (bin/database/)
|
||||||
|
db.DbMaintenance.CreateDatabase();
|
||||||
|
|
||||||
//Use db
|
//Use db
|
||||||
var dt = db.Ado.GetDataTable("select 1");
|
var dt = db.Ado.GetDataTable("select 1");
|
||||||
|
|
||||||
|
//create table OrderDetail
|
||||||
|
db.CodeFirst.InitTables(typeof(OrderItem));
|
||||||
|
|
||||||
|
db.Insertable(new OrderItem() { OrderId = 1, Price = 0 }).ExecuteCommand();
|
||||||
Console.WriteLine("#### SqlSugarClient End ####");
|
Console.WriteLine("#### SqlSugarClient End ####");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Dynamic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@ -11,6 +13,7 @@ namespace OrmTest
|
|||||||
|
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
|
EasyExamples();
|
||||||
QueryConditions();
|
QueryConditions();
|
||||||
JoinTable();
|
JoinTable();
|
||||||
Async();
|
Async();
|
||||||
@ -18,6 +21,83 @@ namespace OrmTest
|
|||||||
Mapper();
|
Mapper();
|
||||||
SqlFuncTest();
|
SqlFuncTest();
|
||||||
Subquery();
|
Subquery();
|
||||||
|
ReturnType();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void EasyExamples()
|
||||||
|
{
|
||||||
|
Console.WriteLine("");
|
||||||
|
Console.WriteLine("#### Examples Start ####");
|
||||||
|
var db = GetInstance();
|
||||||
|
var dbTime = db.GetDate();
|
||||||
|
var getAll = db.Queryable<Order>().ToList();
|
||||||
|
var getOrderBy = db.Queryable<Order>().OrderBy(it => it.Name,OrderByType.Desc).ToList();
|
||||||
|
var getOrderBy2 = db.Queryable<Order>().OrderBy(it => it.Id).OrderBy(it => it.Name, OrderByType.Desc).ToList();
|
||||||
|
var getOrderBy3 = db.Queryable<Order>().OrderBy(it =>new { it.Name,it.Id}).ToList();
|
||||||
|
var getRandom = db.Queryable<Order>().OrderBy(it => SqlFunc.GetRandom()).First();
|
||||||
|
var getByPrimaryKey = db.Queryable<Order>().InSingle(2);
|
||||||
|
var getSingleOrDefault = db.Queryable<Order>().Where(it => it.Id == 1).Single();
|
||||||
|
var getFirstOrDefault = db.Queryable<Order>().First();
|
||||||
|
var getByWhere = db.Queryable<Order>().Where(it => it.Id == 1 || it.Name == "a").ToList();
|
||||||
|
var getByWhere2 = db.Queryable<Order>().Where(it => it.Id == DateTime.Now.Year).ToList();
|
||||||
|
var getByFuns = db.Queryable<Order>().Where(it => SqlFunc.IsNullOrEmpty(it.Name)).ToList();
|
||||||
|
Console.WriteLine("#### Examples End ####");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ReturnType()
|
||||||
|
{
|
||||||
|
Console.WriteLine("");
|
||||||
|
Console.WriteLine("#### ReturnType Start ####");
|
||||||
|
var db = GetInstance();
|
||||||
|
List<Order> list = db.Queryable<Order>().ToList();
|
||||||
|
|
||||||
|
Order item = db.Queryable<Order>().First(it => it.Id == 1);
|
||||||
|
|
||||||
|
DataTable dataTable = db.Queryable<Order>().Select(it => it.Id).ToDataTable();
|
||||||
|
|
||||||
|
var json = db.Queryable<Order>().ToJson();
|
||||||
|
|
||||||
|
List<int> listInt = db.Queryable<Order>().Select(it => it.Id).ToList();
|
||||||
|
|
||||||
|
var dynamic = db.Queryable<Order>().Select<dynamic>().ToList();
|
||||||
|
|
||||||
|
var viewModel = db.Queryable<Order, OrderItem, Custom>((o, i, c) => new JoinQueryInfos(
|
||||||
|
JoinType.Left, o.Id == i.OrderId ,
|
||||||
|
JoinType.Left, o.CustomId == c.Id
|
||||||
|
))
|
||||||
|
.Select<ViewOrder>().ToList();
|
||||||
|
|
||||||
|
var newDynamic = db.Queryable<Order, OrderItem, Custom>((o, i, c) => new JoinQueryInfos(
|
||||||
|
JoinType.Left, o.Id == i.OrderId,
|
||||||
|
JoinType.Left, o.CustomId == c.Id
|
||||||
|
))
|
||||||
|
.Select((o, i, c) => new { orderName = o.Name, cusName=c.Name }).ToList();
|
||||||
|
|
||||||
|
var newClass = db.Queryable<Order, OrderItem, Custom>((o, i, c) => new JoinQueryInfos(
|
||||||
|
JoinType.Left, o.Id == i.OrderId,
|
||||||
|
JoinType.Left, o.CustomId == c.Id
|
||||||
|
))
|
||||||
|
.Select((o, i, c) => new ViewOrder { Name=o.Name, CustomName=c.Name }).ToList();
|
||||||
|
|
||||||
|
|
||||||
|
var oneClass = db.Queryable<Order, OrderItem, Custom>((o, i, c) => new JoinQueryInfos(
|
||||||
|
JoinType.Left, o.Id == i.OrderId,
|
||||||
|
JoinType.Left, o.CustomId == c.Id
|
||||||
|
))
|
||||||
|
.Select((o, i, c) => c).ToList();
|
||||||
|
|
||||||
|
var twoClass = db.Queryable<Order, OrderItem, Custom>((o, i, c) => new JoinQueryInfos(
|
||||||
|
JoinType.Left, o.Id == i.OrderId,
|
||||||
|
JoinType.Left, o.CustomId == c.Id
|
||||||
|
))
|
||||||
|
.Select((o, i, c) => new { o,i}).ToList();
|
||||||
|
|
||||||
|
List<Dictionary<string, object>> ListDic = db.Queryable<Order, OrderItem, Custom>((o, i, c) => new JoinQueryInfos(
|
||||||
|
JoinType.Left, o.Id == i.OrderId,
|
||||||
|
JoinType.Left, o.CustomId == c.Id
|
||||||
|
))
|
||||||
|
.Select<ExpandoObject>().ToList().Select(it => it.ToDictionary(x => x.Key, x => x.Value)).ToList();
|
||||||
|
Console.WriteLine("#### ReturnType End ####");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Subquery()
|
private static void Subquery()
|
||||||
@ -32,6 +112,8 @@ namespace OrmTest
|
|||||||
customName2 = SqlFunc.Subqueryable<Custom>().Where("it.CustomId = id").Where(s => true).Select(s => s.Name)
|
customName2 = SqlFunc.Subqueryable<Custom>().Where("it.CustomId = id").Where(s => true).Select(s => s.Name)
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
|
var list2 = db.Queryable<Order>().Where(it => SqlFunc.Subqueryable<OrderItem>().Where(i => i.OrderId == it.Id).Any()).ToList();
|
||||||
|
|
||||||
Console.WriteLine("#### Subquery End ####");
|
Console.WriteLine("#### Subquery End ####");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,6 +281,8 @@ namespace OrmTest
|
|||||||
var task1 = db.Queryable<Order>().FirstAsync();
|
var task1 = db.Queryable<Order>().FirstAsync();
|
||||||
task1.Wait();
|
task1.Wait();
|
||||||
var task2 = db.Queryable<Order>().Where(it => it.Id == 1).ToListAsync();
|
var task2 = db.Queryable<Order>().Where(it => it.Id == 1).ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
task2.Wait();
|
task2.Wait();
|
||||||
|
|
||||||
Console.WriteLine("#### Async End ####");
|
Console.WriteLine("#### Async End ####");
|
||||||
@ -208,7 +292,7 @@ namespace OrmTest
|
|||||||
{
|
{
|
||||||
return new SqlSugarClient(new ConnectionConfig()
|
return new SqlSugarClient(new ConnectionConfig()
|
||||||
{
|
{
|
||||||
DbType = DbType.SqlServer,
|
DbType = SqlSugar.DbType.SqlServer,
|
||||||
ConnectionString = Config.ConnectionString,
|
ConnectionString = Config.ConnectionString,
|
||||||
InitKeyType = InitKeyType.Attribute,
|
InitKeyType = InitKeyType.Attribute,
|
||||||
IsAutoCloseConnection = true,
|
IsAutoCloseConnection = true,
|
||||||
|
@ -0,0 +1,107 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
public class Demo2_Updateable
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
Console.WriteLine("");
|
||||||
|
Console.WriteLine("#### Updateable Start ####");
|
||||||
|
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||||
|
{
|
||||||
|
DbType = DbType.SqlServer,
|
||||||
|
ConnectionString = Config.ConnectionString,
|
||||||
|
InitKeyType = InitKeyType.Attribute,
|
||||||
|
IsAutoCloseConnection = true,
|
||||||
|
AopEvents = new AopEvents
|
||||||
|
{
|
||||||
|
OnLogExecuting = (sql, p) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(sql);
|
||||||
|
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*** 1.entity or List ***/
|
||||||
|
|
||||||
|
var updateObj = new Order() { Id = 1, Name = "order1" };
|
||||||
|
var updateObjs = new List<Order> {
|
||||||
|
new Order() { Id = 11, Name = "order11" },
|
||||||
|
new Order() { Id = 12, Name = "order12" }
|
||||||
|
};
|
||||||
|
|
||||||
|
//update all columns by primary key
|
||||||
|
var result = db.Updateable(updateObj).ExecuteCommand();//update single
|
||||||
|
var result2 = db.Updateable(updateObjs).ExecuteCommand();//update List<Class>
|
||||||
|
|
||||||
|
//Ignore Name and Price
|
||||||
|
var result3 = db.Updateable(updateObj).IgnoreColumns(it => new { it.CreateTime, it.Price }).ExecuteCommand();
|
||||||
|
|
||||||
|
//only update Name and CreateTime
|
||||||
|
var result4 = db.Updateable(updateObj).UpdateColumns(it => new { it.Name, it.CreateTime }).ExecuteCommand();
|
||||||
|
|
||||||
|
//If there is no primary key
|
||||||
|
var result5 = db.Updateable(updateObj).WhereColumns(it => new { it.Id }).ExecuteCommand();//update single by id
|
||||||
|
var result6 = db.Updateable(updateObjs).WhereColumns(it => new { it.Id }).ExecuteCommand();//update List<Class> by id
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*** 2.by expression ***/
|
||||||
|
|
||||||
|
//update name,createtime
|
||||||
|
var result7 = db.Updateable<Order>(it => new Order() { Name = "a", CreateTime = DateTime.Now }).Where(it => it.Id == 11).ExecuteCommand();
|
||||||
|
var result71 = db.Updateable<Order>().SetColumns(it => new Order() { Name = "a", CreateTime = DateTime.Now }).Where(it => it.Id == 11).ExecuteCommand();
|
||||||
|
//only update name
|
||||||
|
var result8 = db.Updateable<Order>(it => it.Name == "Name" + 1).Where(it => it.Id == 1).ExecuteCommand();
|
||||||
|
var result81 = db.Updateable<Order>().SetColumns(it => it.Name == "Name" + 1).Where(it => it.Id == 1).ExecuteCommand();
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*** 3.by Dictionary ***/
|
||||||
|
var dt = new Dictionary<string, object>();
|
||||||
|
dt.Add("id", 1);
|
||||||
|
dt.Add("name", null);
|
||||||
|
dt.Add("createTime", DateTime.Now);
|
||||||
|
var dtList = new List<Dictionary<string, object>>();
|
||||||
|
dtList.Add(dt);
|
||||||
|
|
||||||
|
var t66 = db.Updateable(dt).AS("student").WhereColumns("id").ExecuteCommand();
|
||||||
|
var t666 = db.Updateable(dtList).AS("student").WhereColumns("id").ExecuteCommand();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*** 4.Other instructions ***/
|
||||||
|
|
||||||
|
var caseValue = "1";
|
||||||
|
//Do not update NULL columns
|
||||||
|
db.Updateable(updateObj).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
||||||
|
|
||||||
|
//if 1 update name else if 2 update name,createtime
|
||||||
|
db.Updateable(updateObj)
|
||||||
|
.UpdateColumnsIF(caseValue == "1", it => new { it.Name })
|
||||||
|
.UpdateColumnsIF(caseValue == "2", it => new { it.Name, it.CreateTime })
|
||||||
|
.ExecuteCommand();
|
||||||
|
//Use Lock
|
||||||
|
db.Updateable(updateObj).With(SqlWith.UpdLock).ExecuteCommand();
|
||||||
|
|
||||||
|
//Where Sql
|
||||||
|
db.Updateable(updateObj).Where("id=@x", new { x = "1" }).ExecuteCommand();
|
||||||
|
|
||||||
|
Console.WriteLine("#### Updateable End ####");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
public class Demo3_Insertable
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
Console.WriteLine("");
|
||||||
|
Console.WriteLine("#### Insertable Start ####");
|
||||||
|
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||||
|
{
|
||||||
|
DbType = DbType.SqlServer,
|
||||||
|
ConnectionString = Config.ConnectionString,
|
||||||
|
InitKeyType = InitKeyType.Attribute,
|
||||||
|
IsAutoCloseConnection = true,
|
||||||
|
AopEvents = new AopEvents
|
||||||
|
{
|
||||||
|
OnLogExecuting = (sql, p) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(sql);
|
||||||
|
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var insertObj = new Order() { Id = 1, Name = "order1" };
|
||||||
|
var updateObjs = new List<Order> {
|
||||||
|
new Order() { Id = 11, Name = "order11" },
|
||||||
|
new Order() { Id = 12, Name = "order12" }
|
||||||
|
};
|
||||||
|
|
||||||
|
//Ignore Price
|
||||||
|
db.Insertable(insertObj).IgnoreColumns(it => new { it.Price }).ExecuteReturnIdentity();//get identity
|
||||||
|
db.Insertable(insertObj).IgnoreColumns("Name", "TestId").ExecuteReturnIdentity();
|
||||||
|
|
||||||
|
//Only insert Name and Price
|
||||||
|
db.Insertable(insertObj).InsertColumns(it => new { it.Name, it.Price }).ExecuteReturnIdentity();
|
||||||
|
db.Insertable(insertObj).InsertColumns("Name", "SchoolId").ExecuteReturnIdentity();
|
||||||
|
|
||||||
|
//ignore null columns
|
||||||
|
db.Insertable(insertObj).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();//get change row count
|
||||||
|
|
||||||
|
//Use Lock
|
||||||
|
db.Insertable(insertObj).With(SqlWith.UpdLock).ExecuteCommand();
|
||||||
|
|
||||||
|
Console.WriteLine("#### Insertable End ####");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
public class Demo4_Deleteable
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
Console.WriteLine("");
|
||||||
|
Console.WriteLine("#### Deleteable Start ####");
|
||||||
|
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||||
|
{
|
||||||
|
DbType = DbType.SqlServer,
|
||||||
|
ConnectionString = Config.ConnectionString,
|
||||||
|
InitKeyType = InitKeyType.Attribute,
|
||||||
|
IsAutoCloseConnection = true,
|
||||||
|
AopEvents = new AopEvents
|
||||||
|
{
|
||||||
|
OnLogExecuting = (sql, p) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(sql);
|
||||||
|
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//by entity
|
||||||
|
db.Deleteable<Order>().Where(new Order() { Id = 1 }).ExecuteCommand();
|
||||||
|
|
||||||
|
//by primary key
|
||||||
|
db.Deleteable<Order>().In(1).ExecuteCommand();
|
||||||
|
|
||||||
|
//by primary key array
|
||||||
|
db.Deleteable<Order>().In(new int[] { 1, 2 }).ExecuteCommand();
|
||||||
|
|
||||||
|
//by expression
|
||||||
|
db.Deleteable<Order>().Where(it => it.Id == 1).ExecuteCommand();
|
||||||
|
|
||||||
|
Console.WriteLine("#### Deleteable End ####");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
using OrmTest.Models;
|
||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
public class Demo5_SqlQueryable
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
Console.WriteLine("");
|
||||||
|
Console.WriteLine("#### SqlQueryable Start ####");
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||||
|
{
|
||||||
|
DbType = DbType.SqlServer,
|
||||||
|
ConnectionString = Config.ConnectionString,
|
||||||
|
InitKeyType = InitKeyType.Attribute,
|
||||||
|
IsAutoCloseConnection = true
|
||||||
|
});
|
||||||
|
|
||||||
|
int total = 0;
|
||||||
|
var list = db.SqlQueryable<Student>("select * from student").ToPageList(1, 2, ref total);
|
||||||
|
|
||||||
|
|
||||||
|
//by expression
|
||||||
|
var list2 = db.SqlQueryable<Student>("select * from student").Where(it => it.Id == 1).ToPageList(1, 2);
|
||||||
|
//by sql
|
||||||
|
var list3 = db.SqlQueryable<Student>("select * from student").Where("id=@id", new { id = 1 }).ToPageList(1, 2);
|
||||||
|
|
||||||
|
Console.WriteLine("#### SqlQueryable End ####");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
public class Demo6_Queue
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
Console.WriteLine("");
|
||||||
|
Console.WriteLine("#### Queue Start ####");
|
||||||
|
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||||
|
{
|
||||||
|
DbType = DbType.SqlServer,
|
||||||
|
ConnectionString = Config.ConnectionString,
|
||||||
|
InitKeyType = InitKeyType.Attribute,
|
||||||
|
IsAutoCloseConnection = true,
|
||||||
|
AopEvents = new AopEvents
|
||||||
|
{
|
||||||
|
OnLogExecuting = (sql, p) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(sql);
|
||||||
|
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
db.Insertable<Order>(new Order() { Name = "a" }).AddQueue();
|
||||||
|
db.Insertable<Order>(new Order() { Name = "b" }).AddQueue();
|
||||||
|
db.SaveQueues();
|
||||||
|
|
||||||
|
|
||||||
|
db.Insertable<Order>(new Order() { Name = "a" }).AddQueue();
|
||||||
|
db.Insertable<Order>(new Order() { Name = "b" }).AddQueue();
|
||||||
|
db.Insertable<Order>(new Order() { Name = "c" }).AddQueue();
|
||||||
|
db.Insertable<Order>(new Order() { Name = "d" }).AddQueue();
|
||||||
|
var ar = db.SaveQueuesAsync();
|
||||||
|
ar.Wait();
|
||||||
|
|
||||||
|
db.Queryable<Order>().AddQueue();
|
||||||
|
db.Queryable<Order>().AddQueue();
|
||||||
|
db.AddQueue("select * from [Order] where id=@id", new { id = 10000 });
|
||||||
|
var result2 = db.SaveQueues<Order, Order, Order>();
|
||||||
|
|
||||||
|
Console.WriteLine("#### Queue End ####");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -65,6 +65,10 @@ namespace OrmTest
|
|||||||
}
|
}
|
||||||
db.DbFirst.IsCreateAttribute().CreateClassFile("c:\\Demo\\8", "Models");
|
db.DbFirst.IsCreateAttribute().CreateClassFile("c:\\Demo\\8", "Models");
|
||||||
|
|
||||||
|
|
||||||
|
//Use Razor Template
|
||||||
|
//db.DbFirst.UseRazorAnalysis(RazorFirst.DefaultRazorClassTemplate).CreateClassFile("");
|
||||||
|
|
||||||
Console.WriteLine("#### DbFirst End ####");
|
Console.WriteLine("#### DbFirst End ####");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ namespace OrmTest
|
|||||||
InitKeyType = InitKeyType.Attribute,
|
InitKeyType = InitKeyType.Attribute,
|
||||||
IsAutoCloseConnection = true
|
IsAutoCloseConnection = true
|
||||||
});
|
});
|
||||||
db.DbMaintenance.CreateDatabase();
|
db.DbMaintenance.CreateDatabase();//default bin/database
|
||||||
db.CodeFirst.InitTables(typeof(CodeFirstTable1));//Create CodeFirstTable1
|
db.CodeFirst.InitTables(typeof(CodeFirstTable1));//Create CodeFirstTable1
|
||||||
db.Insertable(new CodeFirstTable1() { Name = "a", Text="a" }).ExecuteCommand();
|
db.Insertable(new CodeFirstTable1() { Name = "a", Text="a" }).ExecuteCommand();
|
||||||
var list = db.Queryable<CodeFirstTable1>().ToList();
|
var list = db.Queryable<CodeFirstTable1>().ToList();
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
public class CarType
|
||||||
|
{
|
||||||
|
public bool State { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -11,11 +11,11 @@ namespace OrmTest
|
|||||||
//OldTestMain.Init();
|
//OldTestMain.Init();
|
||||||
|
|
||||||
//Demo
|
//Demo
|
||||||
Demo1_SqlSugarClient.Init();
|
//Demo0_SqlSugarClient.Init();
|
||||||
Demo1_Queryable.Init();
|
//Demo1_Queryable.Init();
|
||||||
Democ_GobalFilter.Init();
|
//Democ_GobalFilter.Init();
|
||||||
DemoD_DbFirst.Init();
|
//DemoD_DbFirst.Init();
|
||||||
DemoE_CodeFirst.Init();
|
//DemoE_CodeFirst.Init();
|
||||||
|
|
||||||
//Unit test
|
//Unit test
|
||||||
NewUnitTest.Init();
|
NewUnitTest.Init();
|
||||||
|
@ -25,7 +25,14 @@ namespace OrmTest
|
|||||||
});
|
});
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
|
Updateable();
|
||||||
Json();
|
Json();
|
||||||
|
Ado();
|
||||||
|
Queryable();
|
||||||
|
QueryableAsync();
|
||||||
|
Thread();
|
||||||
|
Thread2();
|
||||||
|
Thread3();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
57
Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/UnitTest/UAdo.cs
Normal file
57
Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/UnitTest/UAdo.cs
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
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 Ado()
|
||||||
|
{
|
||||||
|
|
||||||
|
var task1 = Db.Ado.GetScalarAsync("select 1");
|
||||||
|
task1.Wait();
|
||||||
|
UValidate.Check(1, task1.Result, "ado");
|
||||||
|
|
||||||
|
var task2 = Db.Ado.GetIntAsync("select 2");
|
||||||
|
task2.Wait();
|
||||||
|
UValidate.Check(2, task2.Result, "ado");
|
||||||
|
|
||||||
|
|
||||||
|
var task3 = Db.Ado.GetLongAsync("select 3");
|
||||||
|
task3.Wait();
|
||||||
|
UValidate.Check(3, task3.Result, "ado");
|
||||||
|
|
||||||
|
|
||||||
|
var task4 = Db.Ado.GetDataTableAsync("select 4 as id");
|
||||||
|
task4.Wait();
|
||||||
|
UValidate.Check(4, task4.Result.Rows[0]["id"], "ado");
|
||||||
|
|
||||||
|
|
||||||
|
var task5 = Db.Ado.GetInt("select @id as id",new { id=5});
|
||||||
|
UValidate.Check(5, task5, "ado");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var task6 = Db.Ado.SqlQuery<dynamic>("select @id as id", new { id = 5 });
|
||||||
|
UValidate.Check(5, task6[0].id, "ado");
|
||||||
|
|
||||||
|
|
||||||
|
var task7 = Db.Ado.SqlQueryAsync<dynamic>("select @id as id", new { id = 7 });
|
||||||
|
task7.Wait();
|
||||||
|
UValidate.Check(7, task7.Result[0].id, "ado");
|
||||||
|
|
||||||
|
|
||||||
|
var task8 = Db.Ado.SqlQueryAsync<dynamic>("select 8 as id");
|
||||||
|
task8.Wait();
|
||||||
|
UValidate.Check(8, task8.Result[0].id, "ado");
|
||||||
|
|
||||||
|
var task9=Db.Ado.SqlQuery<Order, OrderItem>("select * from [order];select * from OrderDetail");
|
||||||
|
|
||||||
|
var task10 = Db.Ado.SqlQueryAsync<Order, OrderItem>("select * from [order];select * from OrderDetail");
|
||||||
|
task10.Wait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -15,7 +15,10 @@ namespace OrmTest
|
|||||||
Db.DbMaintenance.TruncateTable<JsonTest>();
|
Db.DbMaintenance.TruncateTable<JsonTest>();
|
||||||
Db.Insertable(new JsonTest() { Order = new Order { Id = 1, Name = "order1" } }).ExecuteCommand();
|
Db.Insertable(new JsonTest() { Order = new Order { Id = 1, Name = "order1" } }).ExecuteCommand();
|
||||||
var list = Db.Queryable<JsonTest>().ToList();
|
var list = Db.Queryable<JsonTest>().ToList();
|
||||||
|
UValidate.Check("order1", list.First().Order.Name, "Json");
|
||||||
Db.Updateable(new JsonTest() { Id = 1, Order = new Order { Id = 2, Name = "order2" } }).ExecuteCommand();
|
Db.Updateable(new JsonTest() { Id = 1, Order = new Order { Id = 2, Name = "order2" } }).ExecuteCommand();
|
||||||
|
list= Db.Queryable<JsonTest>().ToList();
|
||||||
|
UValidate.Check("order2", list.First().Order.Name, "Json");
|
||||||
var list2 = Db.Queryable<JsonTest>().ToList();
|
var list2 = Db.Queryable<JsonTest>().ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
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 Queryable() {
|
||||||
|
|
||||||
|
var pageindex = 1;
|
||||||
|
var pagesize = 10;
|
||||||
|
var total = 0;
|
||||||
|
var totalPage = 0;
|
||||||
|
var list=Db.Queryable<Order>().ToPageList(pageindex, pagesize, ref total, ref totalPage);
|
||||||
|
|
||||||
|
Db.CodeFirst.InitTables(typeof(CarType));
|
||||||
|
Db.Updateable<CarType>()
|
||||||
|
.SetColumns(it => new CarType { State =SqlSugar.SqlFunc.IIF(it.State==true,false,true) }).Where(it=>true)
|
||||||
|
.ExecuteCommand();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SqlSugar;
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
public partial class NewUnitTest
|
||||||
|
{
|
||||||
|
public static void QueryableAsync()
|
||||||
|
{
|
||||||
|
q1();
|
||||||
|
q2();
|
||||||
|
q3();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void q1()
|
||||||
|
{
|
||||||
|
RefAsync<int> total = 0;
|
||||||
|
var count = Db.Queryable<Order>().Count();
|
||||||
|
Task t = Db.Queryable<Order>().ToPageListAsync(1, 2, total);
|
||||||
|
t.Wait();
|
||||||
|
UValidate.Check(count, total.Value, "QueryableAsync");
|
||||||
|
}
|
||||||
|
private static void q2()
|
||||||
|
{
|
||||||
|
RefAsync<int> total = 0;
|
||||||
|
var count = Db.Queryable<Order>().Count();
|
||||||
|
Task t = Db.Queryable<Order>().ToDataTablePageAsync(1, 2, total);
|
||||||
|
t.Wait();
|
||||||
|
UValidate.Check(count, total.Value, "QueryableAsync");
|
||||||
|
}
|
||||||
|
private static void q3()
|
||||||
|
{
|
||||||
|
RefAsync<int> total = 0;
|
||||||
|
var count = Db.Queryable<Order>().Count();
|
||||||
|
Task t = Db.Queryable<Order>().ToJsonPageAsync(1, 2, total);
|
||||||
|
t.Wait();
|
||||||
|
UValidate.Check(count, total.Value, "QueryableAsync");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
378
Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/UnitTest/UThread.cs
Normal file
378
Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/UnitTest/UThread.cs
Normal file
@ -0,0 +1,378 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
public partial class NewUnitTest
|
||||||
|
{
|
||||||
|
|
||||||
|
public static SqlSugarClient simpleDb => new SqlSugarClient(new ConnectionConfig()
|
||||||
|
{
|
||||||
|
DbType = DbType.SqlServer,
|
||||||
|
ConnectionString = Config.ConnectionString,
|
||||||
|
InitKeyType = InitKeyType.Attribute,
|
||||||
|
IsAutoCloseConnection = true,
|
||||||
|
AopEvents = new AopEvents
|
||||||
|
{
|
||||||
|
OnLogExecuting = (sql, p) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(sql);
|
||||||
|
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
public static SqlSugarClient ssDb => new SqlSugarClient(new ConnectionConfig()
|
||||||
|
{
|
||||||
|
DbType = DbType.SqlServer,
|
||||||
|
ConnectionString = Config.ConnectionString,
|
||||||
|
InitKeyType = InitKeyType.Attribute,
|
||||||
|
IsAutoCloseConnection = true,
|
||||||
|
IsShardSameThread = true,
|
||||||
|
AopEvents = new AopEvents
|
||||||
|
{
|
||||||
|
OnLogExecuting = (sql, p) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(sql);
|
||||||
|
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
public static SqlSugarClient singleDb = new SqlSugarClient(new ConnectionConfig()
|
||||||
|
{
|
||||||
|
DbType = DbType.SqlServer,
|
||||||
|
ConnectionString = Config.ConnectionString,
|
||||||
|
InitKeyType = InitKeyType.Attribute,
|
||||||
|
IsAutoCloseConnection = true,
|
||||||
|
AopEvents = new AopEvents
|
||||||
|
{
|
||||||
|
OnLogExecuting = (sql, p) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(sql);
|
||||||
|
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
public static SqlSugarClient singleAndSsDb = new SqlSugarClient(new ConnectionConfig()
|
||||||
|
{
|
||||||
|
DbType = DbType.SqlServer,
|
||||||
|
ConnectionString = Config.ConnectionString,
|
||||||
|
InitKeyType = InitKeyType.Attribute,
|
||||||
|
IsAutoCloseConnection = true,
|
||||||
|
IsShardSameThread = true,
|
||||||
|
AopEvents = new AopEvents
|
||||||
|
{
|
||||||
|
OnLogExecuting = (sql, p) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(sql);
|
||||||
|
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
public static void Thread()
|
||||||
|
{
|
||||||
|
Simple();
|
||||||
|
IsShardSameThread();
|
||||||
|
Single();
|
||||||
|
SingleAndIsShardSameThread();
|
||||||
|
SimpleAsync();
|
||||||
|
IsShardSameThreadAsync();
|
||||||
|
SingleAsync();
|
||||||
|
SingleAndIsShardSameThreadAsync();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Simple()
|
||||||
|
{
|
||||||
|
var t1 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Insertable(new Order() { Name = "test", CreateTime = DateTime.Now }).ExecuteCommand();
|
||||||
|
System.Threading.Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t2 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Insertable(new Order() { Name = "test2", CreateTime = DateTime.Now }).ExecuteCommand();
|
||||||
|
System.Threading.Thread.Sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t3 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Insertable(new Order() { Name = "test3", CreateTime = DateTime.Now }).ExecuteCommand();
|
||||||
|
System.Threading.Thread.Sleep(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
t1.Start();
|
||||||
|
t2.Start();
|
||||||
|
t3.Start();
|
||||||
|
|
||||||
|
Task.WaitAll(t1, t2, t3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SingleAndIsShardSameThread()
|
||||||
|
{
|
||||||
|
var t1 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
singleAndSsDb.Insertable(new Order() { Name = "test", CreateTime = DateTime.Now }).ExecuteCommand();
|
||||||
|
System.Threading.Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t2 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
singleAndSsDb.Insertable(new Order() { Name = "test2", CreateTime = DateTime.Now }).ExecuteCommand();
|
||||||
|
System.Threading.Thread.Sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t3 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
singleAndSsDb.Insertable(new Order() { Name = "test3", CreateTime = DateTime.Now }).ExecuteCommand();
|
||||||
|
System.Threading.Thread.Sleep(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
t1.Start();
|
||||||
|
t2.Start();
|
||||||
|
t3.Start();
|
||||||
|
|
||||||
|
Task.WaitAll(t1, t2, t3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Single()
|
||||||
|
{
|
||||||
|
var t1 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
singleDb.Insertable(new Order() { Name = "test", CreateTime = DateTime.Now }).ExecuteCommand();
|
||||||
|
System.Threading.Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t2 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
singleDb.Insertable(new Order() { Name = "test2", CreateTime = DateTime.Now }).ExecuteCommand();
|
||||||
|
System.Threading.Thread.Sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t3 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
singleDb.Insertable(new Order() { Name = "test3", CreateTime = DateTime.Now }).ExecuteCommand();
|
||||||
|
System.Threading.Thread.Sleep(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
t1.Start();
|
||||||
|
t2.Start();
|
||||||
|
t3.Start();
|
||||||
|
|
||||||
|
Task.WaitAll(t1, t2, t3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void IsShardSameThread()
|
||||||
|
{
|
||||||
|
var t1 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
Db.Insertable(new Order() { Name = "test", CreateTime = DateTime.Now }).ExecuteCommand();
|
||||||
|
System.Threading.Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t2 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
Db.Insertable(new Order() { Name = "test2", CreateTime = DateTime.Now }).ExecuteCommand();
|
||||||
|
System.Threading.Thread.Sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t3 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
Db.Insertable(new Order() { Name = "test3", CreateTime = DateTime.Now }).ExecuteCommand();
|
||||||
|
System.Threading.Thread.Sleep(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
t1.Start();
|
||||||
|
t2.Start();
|
||||||
|
t3.Start();
|
||||||
|
|
||||||
|
Task.WaitAll(t1, t2, t3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static void SimpleAsync()
|
||||||
|
{
|
||||||
|
var t1 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Insertable(new Order() { Name = "test", CreateTime = DateTime.Now }).ExecuteCommandAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t2 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Insertable(new Order() { Name = "test2", CreateTime = DateTime.Now }).ExecuteCommandAsync().Wait(); ;
|
||||||
|
System.Threading.Thread.Sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t3 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Insertable(new Order() { Name = "test3", CreateTime = DateTime.Now }).ExecuteCommandAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
t1.Start();
|
||||||
|
t2.Start();
|
||||||
|
t3.Start();
|
||||||
|
|
||||||
|
Task.WaitAll(t1, t2, t3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SingleAndIsShardSameThreadAsync()
|
||||||
|
{
|
||||||
|
var t1 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
singleAndSsDb.Insertable(new Order() { Name = "test", CreateTime = DateTime.Now }).ExecuteCommandAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t2 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
singleAndSsDb.Insertable(new Order() { Name = "test2", CreateTime = DateTime.Now }).ExecuteCommandAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t3 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
singleAndSsDb.Insertable(new Order() { Name = "test3", CreateTime = DateTime.Now }).ExecuteCommandAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
t1.Start();
|
||||||
|
t2.Start();
|
||||||
|
t3.Start();
|
||||||
|
|
||||||
|
Task.WaitAll(t1, t2, t3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SingleAsync()
|
||||||
|
{
|
||||||
|
var t1 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
singleDb.Insertable(new Order() { Name = "test", CreateTime = DateTime.Now }).ExecuteCommandAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t2 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
singleDb.Insertable(new Order() { Name = "test2", CreateTime = DateTime.Now }).ExecuteCommandAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t3 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
singleDb.Insertable(new Order() { Name = "test3", CreateTime = DateTime.Now }).ExecuteCommandAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
t1.Start();
|
||||||
|
t2.Start();
|
||||||
|
t3.Start();
|
||||||
|
|
||||||
|
Task.WaitAll(t1, t2, t3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void IsShardSameThreadAsync()
|
||||||
|
{
|
||||||
|
var t1 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
Db.Insertable(new Order() { Name = "test", CreateTime = DateTime.Now }).ExecuteCommandAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t2 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
Db.Insertable(new Order() { Name = "test2", CreateTime = DateTime.Now }).ExecuteCommandAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t3 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
Db.Insertable(new Order() { Name = "test3", CreateTime = DateTime.Now }).ExecuteCommandAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
t1.Start();
|
||||||
|
t2.Start();
|
||||||
|
t3.Start();
|
||||||
|
|
||||||
|
Task.WaitAll(t1, t2, t3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
316
Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/UnitTest/UThread2.cs
Normal file
316
Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/UnitTest/UThread2.cs
Normal file
@ -0,0 +1,316 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
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 Thread2()
|
||||||
|
{
|
||||||
|
Simple2();
|
||||||
|
IsShardSameThread2();
|
||||||
|
Single2();
|
||||||
|
SingleAndIsShardSameThread2();
|
||||||
|
SimpleAsync2();
|
||||||
|
IsShardSameThreadAsync2();
|
||||||
|
SingleAsync2();
|
||||||
|
SingleAndIsShardSameThreadAsync2();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Simple2()
|
||||||
|
{
|
||||||
|
var t1 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToList();
|
||||||
|
System.Threading.Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t2 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToList();
|
||||||
|
System.Threading.Thread.Sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t3 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToList();
|
||||||
|
System.Threading.Thread.Sleep(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
t1.Start();
|
||||||
|
t2.Start();
|
||||||
|
t3.Start();
|
||||||
|
|
||||||
|
Task.WaitAll(t1, t2, t3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SingleAndIsShardSameThread2()
|
||||||
|
{
|
||||||
|
var t1 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToList();
|
||||||
|
System.Threading.Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t2 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToList();
|
||||||
|
System.Threading.Thread.Sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t3 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToList();
|
||||||
|
System.Threading.Thread.Sleep(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
t1.Start();
|
||||||
|
t2.Start();
|
||||||
|
t3.Start();
|
||||||
|
|
||||||
|
Task.WaitAll(t1, t2, t3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Single2()
|
||||||
|
{
|
||||||
|
var t1 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToList();
|
||||||
|
System.Threading.Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t2 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToList();
|
||||||
|
System.Threading.Thread.Sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t3 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToList();
|
||||||
|
System.Threading.Thread.Sleep(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
t1.Start();
|
||||||
|
t2.Start();
|
||||||
|
t3.Start();
|
||||||
|
|
||||||
|
Task.WaitAll(t1, t2, t3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void IsShardSameThread2()
|
||||||
|
{
|
||||||
|
var t1 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToList();
|
||||||
|
System.Threading.Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t2 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToList();
|
||||||
|
System.Threading.Thread.Sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t3 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToList();
|
||||||
|
System.Threading.Thread.Sleep(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
t1.Start();
|
||||||
|
t2.Start();
|
||||||
|
t3.Start();
|
||||||
|
|
||||||
|
Task.WaitAll(t1, t2, t3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static void SimpleAsync2()
|
||||||
|
{
|
||||||
|
var t1 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToListAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t2 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToListAsync().Wait(); ;
|
||||||
|
System.Threading.Thread.Sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t3 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToListAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
t1.Start();
|
||||||
|
t2.Start();
|
||||||
|
t3.Start();
|
||||||
|
|
||||||
|
Task.WaitAll(t1, t2, t3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SingleAndIsShardSameThreadAsync2()
|
||||||
|
{
|
||||||
|
var t1 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToListAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t2 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToListAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t3 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToListAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
t1.Start();
|
||||||
|
t2.Start();
|
||||||
|
t3.Start();
|
||||||
|
|
||||||
|
Task.WaitAll(t1, t2, t3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SingleAsync2()
|
||||||
|
{
|
||||||
|
var t1 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToListAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t2 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToListAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t3 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToListAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
t1.Start();
|
||||||
|
t2.Start();
|
||||||
|
t3.Start();
|
||||||
|
|
||||||
|
Task.WaitAll(t1, t2, t3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void IsShardSameThreadAsync2()
|
||||||
|
{
|
||||||
|
var t1 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToListAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t2 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToListAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
var t3 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
simpleDb.Queryable<Order>().Take(10).ToListAsync().Wait();
|
||||||
|
System.Threading.Thread.Sleep(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
t1.Start();
|
||||||
|
t2.Start();
|
||||||
|
t3.Start();
|
||||||
|
|
||||||
|
Task.WaitAll(t1, t2, t3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
117
Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/UnitTest/UThread3.cs
Normal file
117
Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/UnitTest/UThread3.cs
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
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 Thread3()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Thread3");
|
||||||
|
SimpleAsync3();
|
||||||
|
IsShardSameThreadAsync3();
|
||||||
|
SingleAsync3();
|
||||||
|
SingleAndIsShardSameThreadAsync3();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static async Task SimpleAsync3()
|
||||||
|
{
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
await simpleDb.Queryable<Order>().Take(10).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
await simpleDb.Insertable(new Order() { Name = "a", CustomId = 1 }).ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Order> orders = new List<Order>();
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
orders = await simpleDb.Queryable<Order>().Take(10).ToListAsync();
|
||||||
|
}
|
||||||
|
if (orders.Count > 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("async is ok");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task SingleAndIsShardSameThreadAsync3()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
await singleAndSsDb.Queryable<Order>().Take(10).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
await singleAndSsDb.Insertable(new Order() { Name = "a", CustomId = 1 }).ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
List<Order> orders = new List<Order>();
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
orders = await singleAndSsDb.Queryable<Order>().Take(10).ToListAsync();
|
||||||
|
}
|
||||||
|
if (orders.Count > 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("async is ok");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task SingleAsync3()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
await singleDb.Queryable<Order>().Take(10).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
await singleDb.Insertable(new Order() { Name = "a", CustomId = 1 }).ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Order> orders = new List<Order>();
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
orders = await singleDb.Queryable<Order>().Take(10).ToListAsync();
|
||||||
|
}
|
||||||
|
if (orders.Count > 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("async is ok");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task IsShardSameThreadAsync3()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
await ssDb.Queryable<Order>().Take(10).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
await ssDb.Insertable(new Order() { Name = "a", CustomId = 1 }).ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Order> orders = new List<Order>();
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
orders = await ssDb.Queryable<Order>().Take(10).ToListAsync();
|
||||||
|
}
|
||||||
|
if (orders.Count > 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("async is ok");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
public class UValidate
|
||||||
|
{
|
||||||
|
public static void Check(object a, object b, object name)
|
||||||
|
{
|
||||||
|
if (a?.ToString() != b?.ToString())
|
||||||
|
{
|
||||||
|
throw new Exception(name + " error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,90 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
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 Updateable()
|
||||||
|
{
|
||||||
|
Db.CodeFirst.InitTables(typeof(SYS_USER));
|
||||||
|
Db.DbMaintenance.TruncateTable<SYS_USER>();
|
||||||
|
Db.Insertable(new SYS_USER() { USER_ID=1,USER_ACCOUNT = "a", USER_PWD = "b", USER_NAME = "c", PWD_LASTCHTIME = DateTime.Now, PWD_ERRORCOUNT = 1, PWD_LASTERRTIME = DateTime.Now }).ExecuteCommand();
|
||||||
|
Db.Updateable(new SYS_USER() { USER_ID=1, PWD_LASTERRTIME = null }).WhereColumns(it=> new{ it.PWD_ERRORCOUNT, it.PWD_LASTERRTIME }).ExecuteCommand();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 普通用户表
|
||||||
|
/// </summary>
|
||||||
|
[Serializable]
|
||||||
|
public class SYS_USER
|
||||||
|
{
|
||||||
|
private System.Int64? _USER_ID;
|
||||||
|
/// <summary>
|
||||||
|
/// GUID主键
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsPrimaryKey = true, IsIdentity = false)]
|
||||||
|
public System.Int64? USER_ID { get { return this._USER_ID; } set { this._USER_ID = value; } }
|
||||||
|
|
||||||
|
private System.String _USER_ACCOUNT;
|
||||||
|
/// <summary>
|
||||||
|
/// 用户账号,不可重名,即使是假删除了,亦不可重复
|
||||||
|
/// </summary>
|
||||||
|
public System.String USER_ACCOUNT { get { return this._USER_ACCOUNT; } set { this._USER_ACCOUNT = value; } }
|
||||||
|
|
||||||
|
private System.String _USER_PWD;
|
||||||
|
/// <summary>
|
||||||
|
/// 用户密码
|
||||||
|
/// </summary>
|
||||||
|
public System.String USER_PWD
|
||||||
|
{
|
||||||
|
get { return this._USER_PWD; }
|
||||||
|
set { this._USER_PWD = value; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 不允许用户密码序列化,可以反序列化
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool ShouldSerializeUSER_PWD()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private System.String _USER_NAME;
|
||||||
|
/// <summary>
|
||||||
|
/// 用户姓名
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
|
public System.String USER_NAME { get { return this._USER_NAME; } set { this._USER_NAME = value; } }
|
||||||
|
|
||||||
|
private System.Int32 _USER_STATUS;
|
||||||
|
/// <summary>
|
||||||
|
/// 用户状体:10正常;20锁定;99已删除
|
||||||
|
/// </summary>
|
||||||
|
public System.Int32 USER_STATUS { get { return this._USER_STATUS; } set { this._USER_STATUS = value; } }
|
||||||
|
|
||||||
|
private System.DateTime _PWD_LASTCHTIME;
|
||||||
|
/// <summary>
|
||||||
|
/// 最后一次密码更新时间
|
||||||
|
/// </summary>
|
||||||
|
public System.DateTime PWD_LASTCHTIME { get { return this._PWD_LASTCHTIME; } set { this._PWD_LASTCHTIME = value; } }
|
||||||
|
|
||||||
|
private System.Int32? _PWD_ERRORCOUNT;
|
||||||
|
/// <summary>
|
||||||
|
/// 密码错误次数,达到定义的次数就锁定
|
||||||
|
/// </summary>
|
||||||
|
public System.Int32? PWD_ERRORCOUNT { get { return this._PWD_ERRORCOUNT; } set { this._PWD_ERRORCOUNT = value ?? 0; } }
|
||||||
|
|
||||||
|
private System.DateTime? _PWD_LASTERRTIME = null;
|
||||||
|
/// <summary>
|
||||||
|
/// 密码最后一次错误时间,满足定义的时间差之后,可自动解锁,如20分钟后自动解锁,亦作为累次错误次数的时间差比对基础
|
||||||
|
/// 允许为空
|
||||||
|
/// </summary>
|
||||||
|
public System.DateTime? PWD_LASTERRTIME { get { return this._PWD_LASTERRTIME; } set { this._PWD_LASTERRTIME = value; } }
|
||||||
|
}
|
||||||
|
}
|
@ -129,7 +129,7 @@ namespace SqlSugar
|
|||||||
sqlParameter.Size = parameter.Size;
|
sqlParameter.Size = parameter.Size;
|
||||||
sqlParameter.Value = parameter.Value;
|
sqlParameter.Value = parameter.Value;
|
||||||
sqlParameter.DbType = parameter.DbType;
|
sqlParameter.DbType = parameter.DbType;
|
||||||
if (sqlParameter.Value!=null&&sqlParameter.DbType == System.Data.DbType.DateTime)
|
if (sqlParameter.Value!=null&& sqlParameter.Value != DBNull.Value && sqlParameter.DbType == System.Data.DbType.DateTime)
|
||||||
{
|
{
|
||||||
var date = Convert.ToDateTime(sqlParameter.Value);
|
var date = Convert.ToDateTime(sqlParameter.Value);
|
||||||
if (date==DateTime.MinValue)
|
if (date==DateTime.MinValue)
|
||||||
|
Loading…
Reference in New Issue
Block a user