mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 13:06:50 +08:00
Update demo
This commit is contained in:
parent
a6445641af
commit
e21aa5d0f0
@ -32,15 +32,11 @@ namespace OrmTest
|
|||||||
|
|
||||||
|
|
||||||
//insert or update
|
//insert or update
|
||||||
db.Saveable<Order>(new Order() { Id=1, Name="jack" }).ExecuteReturnEntity();
|
var x= db.Storageable<Order>(new Order() { Id=1, Name="jack" }).ToStorage();
|
||||||
|
x.AsUpdateable.ExecuteCommand();
|
||||||
|
x.AsInsertable.ExecuteCommand();
|
||||||
//insert or update
|
|
||||||
db.Saveable<Order>(new Order() { Id = 1000, Name = "jack", CreateTime=DateTime.Now })
|
|
||||||
.InsertColumns(it => new { it.Name,it.CreateTime, it.Price})//if insert into name,CreateTime,Price
|
|
||||||
.UpdateColumns(it => new { it.Name, it.CreateTime })//if update set name CreateTime
|
|
||||||
.ExecuteReturnEntity();
|
|
||||||
|
|
||||||
|
|
||||||
Console.WriteLine("");
|
Console.WriteLine("");
|
||||||
Console.WriteLine("#### Saveable End ####");
|
Console.WriteLine("#### Saveable End ####");
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,9 @@ namespace OrmTest
|
|||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
Console.WriteLine("");
|
Console.WriteLine("");
|
||||||
Console.WriteLine("#### SimpleClient Start ####");
|
Console.WriteLine("#### DemoH_Tenant Start ####");
|
||||||
new C1Service().Test();
|
new C1Service().Test();
|
||||||
Console.WriteLine("#### SimpleClient End ####");
|
Console.WriteLine("#### DemoH_Tenant End ####");
|
||||||
}
|
}
|
||||||
public class C1Service : Repository<C1Table>
|
public class C1Service : Repository<C1Table>
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@ namespace OrmTest
|
|||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
Console.WriteLine("");
|
Console.WriteLine("");
|
||||||
Console.WriteLine("#### Utilities Start ####");
|
Console.WriteLine("#### DemoJ_Report Start ####");
|
||||||
|
|
||||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@ namespace OrmTest
|
|||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
Console.WriteLine("");
|
Console.WriteLine("");
|
||||||
Console.WriteLine("#### Utilities Start ####");
|
Console.WriteLine("#### DemoL_Snowflake ####");
|
||||||
|
|
||||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||||
{
|
{
|
||||||
|
72
Src/Asp.Net/SqlServerTest/Demo/DemoM_UnitOfWork.cs
Normal file
72
Src/Asp.Net/SqlServerTest/Demo/DemoM_UnitOfWork.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
public class DemoM_UnitOfWork
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
Console.WriteLine("");
|
||||||
|
Console.WriteLine("#### DemoM_UnitOfWork ####");
|
||||||
|
|
||||||
|
|
||||||
|
DbContext.Db.UseTran(() =>
|
||||||
|
{
|
||||||
|
|
||||||
|
var id = DbContext.CustomDal.InsertReturnIdentity(new Custom() { Id = 1, Name = "guid" });
|
||||||
|
var id2 = DbContext.OrderDal.InsertReturnIdentity(new Order() { Name = "guid2", Price = 0, CreateTime = DateTime.Now, CustomId = 1 });
|
||||||
|
throw new Exception("");
|
||||||
|
},
|
||||||
|
e =>
|
||||||
|
{
|
||||||
|
//throw e;
|
||||||
|
});
|
||||||
|
Console.WriteLine("");
|
||||||
|
Console.WriteLine("#### Saveable End ####");
|
||||||
|
}
|
||||||
|
public class DbContext
|
||||||
|
{
|
||||||
|
public static SqlSugarScope Db = new SqlSugarScope(new ConnectionConfig()
|
||||||
|
{
|
||||||
|
DbType = SqlSugar.DbType.SqlServer,
|
||||||
|
ConnectionString = Config.ConnectionString,
|
||||||
|
IsAutoCloseConnection = true
|
||||||
|
}, db => {
|
||||||
|
//单例参数配置,所有上下文生效
|
||||||
|
db.Aop.OnLogExecuting = (s, p) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(s);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
public static DbSet<Order> OrderDal => new DbSet<Order>();
|
||||||
|
public static DbSet<Custom> CustomDal => new DbSet<Custom>();
|
||||||
|
|
||||||
|
|
||||||
|
public class DbSet<T> : SimpleClient<T> where T : class, new()
|
||||||
|
{
|
||||||
|
public DbSet(ISqlSugarClient context = null) : base(context)//需要有构造参数
|
||||||
|
{
|
||||||
|
base.Context = DbContext.Db;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 扩展方法,自带方法不能满足的时候可以添加新方法
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public List<T> CommQuery(string json)
|
||||||
|
{
|
||||||
|
//base.Context.Queryable<T>().ToList();可以拿到SqlSugarClient 做复杂操作
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -33,6 +33,7 @@ namespace OrmTest
|
|||||||
DemoH_Tenant.Init();
|
DemoH_Tenant.Init();
|
||||||
DemoJ_Report.Init();
|
DemoJ_Report.Init();
|
||||||
DemoL_Snowflake.Init();
|
DemoL_Snowflake.Init();
|
||||||
|
DemoM_UnitOfWork.Init();
|
||||||
//Unit test
|
//Unit test
|
||||||
//NewUnitTest.Init();
|
//NewUnitTest.Init();
|
||||||
|
|
||||||
|
@ -81,6 +81,7 @@
|
|||||||
<Compile Include="Demo\DemoH_Tenant.cs" />
|
<Compile Include="Demo\DemoH_Tenant.cs" />
|
||||||
<Compile Include="Demo\DemoJ_Report.cs" />
|
<Compile Include="Demo\DemoJ_Report.cs" />
|
||||||
<Compile Include="Demo\DemoL_Snowflake.cs" />
|
<Compile Include="Demo\DemoL_Snowflake.cs" />
|
||||||
|
<Compile Include="Demo\DemoM_UnitOfWork.cs" />
|
||||||
<Compile Include="Models\DataDictionary.cs" />
|
<Compile Include="Models\DataDictionary.cs" />
|
||||||
<Compile Include="Models\Custom.cs" />
|
<Compile Include="Models\Custom.cs" />
|
||||||
<Compile Include="Models\EntityMapper.cs" />
|
<Compile Include="Models\EntityMapper.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user