mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-21 02:58:05 +08:00
Update Demo
This commit is contained in:
@@ -143,6 +143,7 @@
|
|||||||
<Compile Include="UnitTest\ObjectsValidate.cs" />
|
<Compile Include="UnitTest\ObjectsValidate.cs" />
|
||||||
<Compile Include="UnitTest\UJson.cs" />
|
<Compile Include="UnitTest\UJson.cs" />
|
||||||
<Compile Include="UnitTest\Main.cs" />
|
<Compile Include="UnitTest\Main.cs" />
|
||||||
|
<Compile Include="UnitTest\UThread.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\SqlSugar\SqlSugar.csproj">
|
<ProjectReference Include="..\SqlSugar\SqlSugar.csproj">
|
||||||
|
@@ -26,6 +26,7 @@ namespace OrmTest
|
|||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
Json();
|
Json();
|
||||||
|
Thread();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@ namespace OrmTest
|
|||||||
{
|
{
|
||||||
if (a?.ToString() != b?.ToString())
|
if (a?.ToString() != b?.ToString())
|
||||||
{
|
{
|
||||||
new Exception(name+" error");
|
throw new Exception(name + " error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@ namespace OrmTest
|
|||||||
var list = Db.Queryable<JsonTest>().ToList();
|
var list = Db.Queryable<JsonTest>().ToList();
|
||||||
ObjectsValidate.Check("order1", list.First().Order.Name, "Json");
|
ObjectsValidate.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();
|
||||||
ObjectsValidate.Check("order2", list.First().Order.Name, "Json");
|
ObjectsValidate.Check("order2", list.First().Order.Name, "Json");
|
||||||
var list2 = Db.Queryable<JsonTest>().ToList();
|
var list2 = Db.Queryable<JsonTest>().ToList();
|
||||||
}
|
}
|
||||||
|
228
Src/Asp.Net/SqlServerTest/UnitTest/UThread.cs
Normal file
228
Src/Asp.Net/SqlServerTest/UnitTest/UThread.cs
Normal file
@@ -0,0 +1,228 @@
|
|||||||
|
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 tdb0 => 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 tdb1 => 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 tdb2 = 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 tdb3 = 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();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Simple()
|
||||||
|
{
|
||||||
|
var t1 = new Task(() =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
tdb0.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++)
|
||||||
|
{
|
||||||
|
tdb0.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++)
|
||||||
|
{
|
||||||
|
tdb0.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++)
|
||||||
|
{
|
||||||
|
tdb3.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++)
|
||||||
|
{
|
||||||
|
tdb3.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++)
|
||||||
|
{
|
||||||
|
tdb3.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++)
|
||||||
|
{
|
||||||
|
tdb2.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++)
|
||||||
|
{
|
||||||
|
tdb2.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++)
|
||||||
|
{
|
||||||
|
tdb2.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Reference in New Issue
Block a user