mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 13:16:37 +08:00
Update Demo
This commit is contained in:
parent
5903462ec4
commit
73dc46458e
7
Src/Asp.Net/OracleTest/Models/CarType.cs
Normal file
7
Src/Asp.Net/OracleTest/Models/CarType.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace OrmTest
|
||||
{
|
||||
public class CarType
|
||||
{
|
||||
public bool State { get; set; }
|
||||
}
|
||||
}
|
14
Src/Asp.Net/OracleTest/Models/Custom.cs
Normal file
14
Src/Asp.Net/OracleTest/Models/Custom.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class Custom
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
20
Src/Asp.Net/OracleTest/Models/Mappers.cs
Normal file
20
Src/Asp.Net/OracleTest/Models/Mappers.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class Tree
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey =true)]
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||
public Tree Parent { get; set; }
|
||||
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||
public List<Tree> Child { get; set; }
|
||||
}
|
||||
}
|
20
Src/Asp.Net/OracleTest/Models/MyCustomAttributeTable.cs
Normal file
20
Src/Asp.Net/OracleTest/Models/MyCustomAttributeTable.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
[Table("CustomAttributeTable")]
|
||||
//[SugarTable("CustomAttributeTable")]
|
||||
public class MyCustomAttributeTable
|
||||
{
|
||||
|
||||
[Key]
|
||||
//[SugarColumn(IsPrimaryKey =true)]
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
21
Src/Asp.Net/OracleTest/Models/Order.cs
Normal file
21
Src/Asp.Net/OracleTest/Models/Order.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
|
||||
public class Order
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
public decimal Price { get; set; }
|
||||
[SqlSugar.SugarColumn(IsNullable = true)]
|
||||
public DateTime CreateTime { get; set; }
|
||||
[SqlSugar.SugarColumn(IsNullable =true)]
|
||||
public int CustomId { get; set; }
|
||||
}
|
||||
}
|
18
Src/Asp.Net/OracleTest/Models/OrderItem.cs
Normal file
18
Src/Asp.Net/OracleTest/Models/OrderItem.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
[SqlSugar.SugarTable("OrderDetail")]
|
||||
public class OrderItem
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey =true, IsIdentity =true)]
|
||||
public int ItemId { get; set; }
|
||||
public int OrderId { get; set; }
|
||||
public decimal? Price { get; set; }
|
||||
[SqlSugar.SugarColumn(IsNullable = true)]
|
||||
public DateTime? CreateTime { get; set; }
|
||||
}
|
||||
}
|
17
Src/Asp.Net/OracleTest/Models/TestTree.cs
Normal file
17
Src/Asp.Net/OracleTest/Models/TestTree.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class TestTree
|
||||
{
|
||||
[SqlSugar.SugarColumn(ColumnDataType = "hierarchyid")]
|
||||
public string TreeId { get; set; }
|
||||
[SqlSugar.SugarColumn(ColumnDataType = "Geography")]
|
||||
public string GId { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
13
Src/Asp.Net/OracleTest/Models/ViewOrder.cs
Normal file
13
Src/Asp.Net/OracleTest/Models/ViewOrder.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class ViewOrder:Order
|
||||
{
|
||||
public string CustomName { get; set; }
|
||||
}
|
||||
}
|
36
Src/Asp.Net/OracleTest/OldTest/Program.cs
Normal file
36
Src/Asp.Net/OracleTest/OldTest/Program.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq.Expressions;
|
||||
using SqlSugar;
|
||||
using OrmTest.Models;
|
||||
using System.Data.SqlClient;
|
||||
using OrmTest.UnitTest;
|
||||
using OrmTest.PerformanceTesting;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class OldTestMain
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
|
||||
/***Unit Test***/
|
||||
new Select(1).Init();
|
||||
new Field(1).Init();
|
||||
/***Demo***/
|
||||
OrmTest.Demo.Query.Init();
|
||||
OrmTest.Demo.Insert.Init();
|
||||
//OrmTest.Demo.Delete.Init();
|
||||
OrmTest.Demo.Update.Init();
|
||||
OrmTest.Demo.DbFirst.Init();
|
||||
OrmTest.Demo.JoinSql.Init();
|
||||
OrmTest.Demo.Filter.Init();
|
||||
OrmTest.Demo.ComplexModel.Init();
|
||||
OrmTest.Demo.CodeFirst.Init();
|
||||
}
|
||||
}
|
||||
}
|
@ -37,6 +37,7 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="SyntacticSugar, Version=2.4.1.0, Culture=neutral, processorArchitecture=MSIL" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
@ -46,47 +47,67 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Config.cs" />
|
||||
<Compile Include="Demos\1_Query.cs" />
|
||||
<Compile Include="Demos\2_Update.cs" />
|
||||
<Compile Include="Demos\3_Insert.cs" />
|
||||
<Compile Include="Demos\4_Delete.cs" />
|
||||
<Compile Include="Demos\5_CodeFirst.cs" />
|
||||
<Compile Include="Demos\5_DbFirst.cs" />
|
||||
<Compile Include="Demos\6_ComplexModel.cs" />
|
||||
<Compile Include="Demos\7_Filter.cs" />
|
||||
<Compile Include="Demos\8_JoinSql.cs" />
|
||||
<Compile Include="Demos\DemoBase.cs" />
|
||||
<Compile Include="Models\DataTestInfo.cs" />
|
||||
<Compile Include="Models\DataTestInfo2.cs" />
|
||||
<Compile Include="Models\Enum.cs" />
|
||||
<Compile Include="Models\School.cs" />
|
||||
<Compile Include="Models\Student.cs" />
|
||||
<Compile Include="Models\ViewModelStudent.cs" />
|
||||
<Compile Include="PerformanceTesting\PerformanceBase.cs" />
|
||||
<Compile Include="PerformanceTesting\SqlSugarPerformance.cs" />
|
||||
<Compile Include="Models\CarType.cs" />
|
||||
<Compile Include="Models\Custom.cs" />
|
||||
<Compile Include="Models\Mappers.cs" />
|
||||
<Compile Include="Models\MyCustomAttributeTable.cs" />
|
||||
<Compile Include="Models\Order.cs" />
|
||||
<Compile Include="Models\OrderItem.cs" />
|
||||
<Compile Include="Models\TestTree.cs" />
|
||||
<Compile Include="Models\ViewOrder.cs" />
|
||||
<Compile Include="OldTest\Demos\1_Query.cs" />
|
||||
<Compile Include="OldTest\Demos\2_Update.cs" />
|
||||
<Compile Include="OldTest\Demos\3_Insert.cs" />
|
||||
<Compile Include="OldTest\Demos\4_Delete.cs" />
|
||||
<Compile Include="OldTest\Demos\5_CodeFirst.cs" />
|
||||
<Compile Include="OldTest\Demos\5_DbFirst.cs" />
|
||||
<Compile Include="OldTest\Demos\6_ComplexModel.cs" />
|
||||
<Compile Include="OldTest\Demos\7_Filter.cs" />
|
||||
<Compile Include="OldTest\Demos\8_JoinSql.cs" />
|
||||
<Compile Include="OldTest\Demos\DemoBase.cs" />
|
||||
<Compile Include="OldTest\Models\DataTestInfo.cs" />
|
||||
<Compile Include="OldTest\Models\DataTestInfo2.cs" />
|
||||
<Compile Include="OldTest\Models\Enum.cs" />
|
||||
<Compile Include="OldTest\Models\School.cs" />
|
||||
<Compile Include="OldTest\Models\Student.cs" />
|
||||
<Compile Include="OldTest\Models\ViewModelStudent.cs" />
|
||||
<Compile Include="OldTest\PerformanceTesting\PerformanceBase.cs" />
|
||||
<Compile Include="OldTest\PerformanceTesting\SqlSugarPerformance.cs" />
|
||||
<Compile Include="OldTest\Program.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="UnitTest\DataTest.cs" />
|
||||
<Compile Include="UnitTest\Delete.cs" />
|
||||
<Compile Include="UnitTest\EnumTest.cs" />
|
||||
<Compile Include="UnitTest\ExpressionTest\Field.cs" />
|
||||
<Compile Include="UnitTest\ExpressionTest\Method.cs" />
|
||||
<Compile Include="UnitTest\ExpressionTest\Select.cs" />
|
||||
<Compile Include="UnitTest\ExpressionTest\Where.cs" />
|
||||
<Compile Include="UnitTest\Insert.cs" />
|
||||
<Compile Include="UnitTest\Mapping .cs" />
|
||||
<Compile Include="UnitTest\Query\JoinQuery.cs" />
|
||||
<Compile Include="UnitTest\Query\SelectQuery.cs" />
|
||||
<Compile Include="UnitTest\Query\SingleQuery.cs" />
|
||||
<Compile Include="UnitTest\Setting\Attribute.cs" />
|
||||
<Compile Include="UnitTest\Setting\AutoClose.cs" />
|
||||
<Compile Include="UnitTest\Setting\MapColumn.cs" />
|
||||
<Compile Include="UnitTest\Setting\MapTable.cs" />
|
||||
<Compile Include="UnitTest\UnitTestBase.cs" />
|
||||
<Compile Include="UnitTest\Update.cs" />
|
||||
<Compile Include="OldTest\UnitTest\DataTest.cs" />
|
||||
<Compile Include="OldTest\UnitTest\Delete.cs" />
|
||||
<Compile Include="OldTest\UnitTest\EnumTest.cs" />
|
||||
<Compile Include="OldTest\UnitTest\ExpressionTest\Field.cs" />
|
||||
<Compile Include="OldTest\UnitTest\ExpressionTest\Method.cs" />
|
||||
<Compile Include="OldTest\UnitTest\ExpressionTest\Select.cs" />
|
||||
<Compile Include="OldTest\UnitTest\ExpressionTest\Where.cs" />
|
||||
<Compile Include="OldTest\UnitTest\Insert.cs" />
|
||||
<Compile Include="OldTest\UnitTest\Mapping .cs" />
|
||||
<Compile Include="OldTest\UnitTest\Query\JoinQuery.cs" />
|
||||
<Compile Include="OldTest\UnitTest\Query\SelectQuery.cs" />
|
||||
<Compile Include="OldTest\UnitTest\Query\SingleQuery.cs" />
|
||||
<Compile Include="OldTest\UnitTest\Setting\Attribute.cs" />
|
||||
<Compile Include="OldTest\UnitTest\Setting\AutoClose.cs" />
|
||||
<Compile Include="OldTest\UnitTest\Setting\MapColumn.cs" />
|
||||
<Compile Include="OldTest\UnitTest\Setting\MapTable.cs" />
|
||||
<Compile Include="OldTest\UnitTest\UnitTestBase.cs" />
|
||||
<Compile Include="OldTest\UnitTest\Update.cs" />
|
||||
<Compile Include="UnitTest\Main.cs" />
|
||||
<Compile Include="UnitTest\UAdo.cs" />
|
||||
<Compile Include="UnitTest\UCodeFirst.cs" />
|
||||
<Compile Include="UnitTest\UJson.cs" />
|
||||
<Compile Include="UnitTest\Updateable.cs" />
|
||||
<Compile Include="UnitTest\UQueryable.cs" />
|
||||
<Compile Include="UnitTest\UQueryableAsync.cs" />
|
||||
<Compile Include="UnitTest\UThread.cs" />
|
||||
<Compile Include="UnitTest\UThread2.cs" />
|
||||
<Compile Include="UnitTest\UThread3.cs" />
|
||||
<Compile Include="UnitTest\UValidate.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="OtherDll\SyntacticSugar.dll" />
|
||||
<Content Include="OldTest\OtherDll\SyntacticSugar.dll" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SqlSugar\SqlSugar.csproj">
|
||||
@ -95,7 +116,7 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="DataBase\" />
|
||||
<Folder Include="OldTest\DataBase\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
|
@ -1,15 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq.Expressions;
|
||||
using SqlSugar;
|
||||
using OrmTest.Models;
|
||||
using System.Data.SqlClient;
|
||||
using OrmTest.PerformanceTesting;
|
||||
using OrmTest.UnitTest;
|
||||
using OrmTest.PerformanceTesting;
|
||||
using System;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
@ -17,21 +8,15 @@ namespace OrmTest
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
OldTestMain.Init();
|
||||
|
||||
//Unit test
|
||||
NewUnitTest.Init();
|
||||
|
||||
/***Unit Test***/
|
||||
new Select(1).Init();
|
||||
new Field(1).Init();
|
||||
|
||||
/***Demo***/
|
||||
OrmTest.Demo.Query.Init();
|
||||
OrmTest.Demo.Insert.Init();
|
||||
//OrmTest.Demo.Delete.Init();
|
||||
OrmTest.Demo.Update.Init();
|
||||
OrmTest.Demo.DbFirst.Init();
|
||||
OrmTest.Demo.JoinSql.Init();
|
||||
OrmTest.Demo.Filter.Init();
|
||||
OrmTest.Demo.ComplexModel.Init();
|
||||
OrmTest.Demo.CodeFirst.Init();
|
||||
Console.WriteLine("all successfully.");
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
39
Src/Asp.Net/OracleTest/UnitTest/Main.cs
Normal file
39
Src/Asp.Net/OracleTest/UnitTest/Main.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public partial class NewUnitTest
|
||||
{
|
||||
public static SqlSugarClient Db=> new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.Oracle,
|
||||
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 void Init()
|
||||
{
|
||||
CodeFirst();
|
||||
Updateable();
|
||||
Json();
|
||||
Ado();
|
||||
Queryable();
|
||||
QueryableAsync();
|
||||
Thread();
|
||||
Thread2();
|
||||
Thread3();
|
||||
}
|
||||
}
|
||||
}
|
57
Src/Asp.Net/OracleTest/UnitTest/UAdo.cs
Normal file
57
Src/Asp.Net/OracleTest/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 from dual");
|
||||
task1.Wait();
|
||||
UValidate.Check(1, task1.Result, "ado");
|
||||
|
||||
var task2 = Db.Ado.GetIntAsync("select 2 from dual");
|
||||
task2.Wait();
|
||||
UValidate.Check(2, task2.Result, "ado");
|
||||
|
||||
|
||||
var task3 = Db.Ado.GetLongAsync("select 3 from dual");
|
||||
task3.Wait();
|
||||
UValidate.Check(3, task3.Result, "ado");
|
||||
|
||||
|
||||
var task4 = Db.Ado.GetDataTableAsync("select 4 as id from dual");
|
||||
task4.Wait();
|
||||
UValidate.Check(4, task4.Result.Rows[0]["id"], "ado");
|
||||
|
||||
|
||||
var task5 = Db.Ado.GetInt("select @id as id from dual", new { id=5});
|
||||
UValidate.Check(5, task5, "ado");
|
||||
|
||||
|
||||
|
||||
var task6 = Db.Ado.SqlQuery<dynamic>("select @id as id from dual", new { id = 5 });
|
||||
UValidate.Check(5, task6[0].id, "ado");
|
||||
|
||||
|
||||
var task7 = Db.Ado.SqlQueryAsync<dynamic>("select @id as id from dual", new { id = 7 });
|
||||
task7.Wait();
|
||||
UValidate.Check(7, task7.Result[0].id, "ado");
|
||||
|
||||
|
||||
var task8 = Db.Ado.SqlQueryAsync<dynamic>("select 8 as id from dual");
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
25
Src/Asp.Net/OracleTest/UnitTest/UCodeFirst.cs
Normal file
25
Src/Asp.Net/OracleTest/UnitTest/UCodeFirst.cs
Normal file
@ -0,0 +1,25 @@
|
||||
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 CodeFirst()
|
||||
{
|
||||
if (Db.DbMaintenance.IsAnyTable("UnitCodeTest1", false))
|
||||
Db.DbMaintenance.DropTable("UnitCodeTest1");
|
||||
Db.CodeFirst.InitTables<UnitCodeTest1>();
|
||||
}
|
||||
public class UnitCodeTest1
|
||||
{
|
||||
[SqlSugar.SugarColumn(IndexGroupNameList = new string[] { "group1" })]
|
||||
public int Id { get; set; }
|
||||
[SqlSugar.SugarColumn(DefaultValue="getdate()", IndexGroupNameList =new string[] {"group1" } )]
|
||||
public DateTime? CreateDate { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
34
Src/Asp.Net/OracleTest/UnitTest/UJson.cs
Normal file
34
Src/Asp.Net/OracleTest/UnitTest/UJson.cs
Normal file
@ -0,0 +1,34 @@
|
||||
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 Json()
|
||||
{
|
||||
Db.CodeFirst.InitTables<JsonTest>();
|
||||
Db.DbMaintenance.TruncateTable<JsonTest>();
|
||||
Db.Insertable(new JsonTest() { Order = new Order { Id = 1, Name = "order1" } }).ExecuteCommand();
|
||||
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();
|
||||
list= Db.Queryable<JsonTest>().ToList();
|
||||
UValidate.Check("order2", list.First().Order.Name, "Json");
|
||||
var list2 = Db.Queryable<JsonTest>().ToList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class JsonTest
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
[SqlSugar.SugarColumn(ColumnDataType = "varchar(max)", IsJson = true)]
|
||||
public Order Order { get; set; }
|
||||
}
|
||||
}
|
39
Src/Asp.Net/OracleTest/UnitTest/UQueryable.cs
Normal file
39
Src/Asp.Net/OracleTest/UnitTest/UQueryable.cs
Normal file
@ -0,0 +1,39 @@
|
||||
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();
|
||||
|
||||
//Db.CodeFirst.InitTables(typeof(TestTree));
|
||||
//Db.DbMaintenance.TruncateTable<TestTree>();
|
||||
//Db.Ado.ExecuteCommand("insert testtree values(hierarchyid::GetRoot(),geography :: STGeomFromText ('POINT(55.9271035250276 -3.29431266523898)',4326),'name')");
|
||||
//var list2 = Db.Queryable<TestTree>().ToList();
|
||||
|
||||
Db.CodeFirst.InitTables<GuidTable>();
|
||||
Db.Queryable<GuidTable>().Where(it => it.Id.HasValue).ToList();
|
||||
}
|
||||
|
||||
|
||||
public class GuidTable
|
||||
{
|
||||
public Guid? Id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
43
Src/Asp.Net/OracleTest/UnitTest/UQueryableAsync.cs
Normal file
43
Src/Asp.Net/OracleTest/UnitTest/UQueryableAsync.cs
Normal file
@ -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.Net/OracleTest/UnitTest/UThread.cs
Normal file
378
Src/Asp.Net/OracleTest/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.Net/OracleTest/UnitTest/UThread2.cs
Normal file
316
Src/Asp.Net/OracleTest/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.Net/OracleTest/UnitTest/UThread3.cs
Normal file
117
Src/Asp.Net/OracleTest/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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
19
Src/Asp.Net/OracleTest/UnitTest/UValidate.cs
Normal file
19
Src/Asp.Net/OracleTest/UnitTest/UValidate.cs
Normal file
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
90
Src/Asp.Net/OracleTest/UnitTest/Updateable.cs
Normal file
90
Src/Asp.Net/OracleTest/UnitTest/Updateable.cs
Normal file
@ -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; } }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user