mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Update insert nav
This commit is contained in:
parent
55305ec54b
commit
69cd3815f2
@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class InsertNavTaskInit<Root, T> where T : class, new() where Root : class, new()
|
||||
{
|
||||
|
||||
public SqlSugarProvider Context { get; set; }
|
||||
public InsertNavProvider<Root, Root> insertNavProvider { get; set; }
|
||||
|
||||
public InsertNavTask<Root, TChild> ThenInclude<TChild>(Expression<Func<Root, TChild>> expression) where TChild : class, new()
|
||||
{
|
||||
this.Context = insertNavProvider._Context;
|
||||
InsertNavTask<Root, TChild> result = new InsertNavTask<Root, TChild>();
|
||||
Func<InsertNavProvider<Root, TChild>> func = () => insertNavProvider.ThenInclude(expression);
|
||||
result.PreFunc = func;
|
||||
result.Context = this.Context;
|
||||
return result;
|
||||
}
|
||||
public InsertNavTask<Root, TChild> ThenInclude<TChild>(Expression<Func<Root, List<TChild>>> expression) where TChild : class, new()
|
||||
{
|
||||
this.Context = insertNavProvider._Context;
|
||||
InsertNavTask<Root, TChild> result = new InsertNavTask<Root, TChild>();
|
||||
Func<InsertNavProvider<Root, TChild>> func = () => insertNavProvider.ThenInclude(expression);
|
||||
result.PreFunc = func;
|
||||
result.Context = this.Context;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public class InsertNavTask<Root, T> where T : class, new() where Root : class, new()
|
||||
{
|
||||
public SqlSugarProvider Context { get; set; }
|
||||
public Func<InsertNavProvider<Root, T>> PreFunc { get; set; }
|
||||
public InsertNavTask<Root, TChild> ThenInclude<TChild>(Expression<Func<T, TChild>> expression) where TChild : class, new()
|
||||
{
|
||||
InsertNavTask<Root, TChild> result = new InsertNavTask<Root, TChild>();
|
||||
Func<InsertNavProvider<Root, TChild>> func = () => PreFunc().ThenInclude(expression);
|
||||
result.PreFunc = func;
|
||||
result.Context = this.Context;
|
||||
return result;
|
||||
}
|
||||
public InsertNavTask<Root, TChild> ThenInclude<TChild>(Expression<Func<T, List<TChild>>> expression) where TChild : class, new()
|
||||
{
|
||||
InsertNavTask<Root, TChild> result = new InsertNavTask<Root, TChild>();
|
||||
Func<InsertNavProvider<Root, TChild>> func = () => PreFunc().ThenInclude(expression);
|
||||
result.PreFunc = func;
|
||||
result.Context = this.Context;
|
||||
return result;
|
||||
}
|
||||
public void ExecuteCommand()
|
||||
{
|
||||
var hasTran = this.Context.Ado.Transaction != null;
|
||||
if (hasTran)
|
||||
{
|
||||
PreFunc();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Context.Ado.UseTran(() =>
|
||||
{
|
||||
PreFunc();
|
||||
}, ex => throw ex);
|
||||
}
|
||||
}
|
||||
public async Task ExecuteCommandAsync()
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
ExecuteCommand();
|
||||
await Task.Delay(0);
|
||||
});
|
||||
}
|
||||
|
||||
public InsertNavTask<Root, Root> AsNav()
|
||||
{
|
||||
InsertNavTask<Root, Root> result = new InsertNavTask<Root, Root>();
|
||||
Func<InsertNavProvider<Root, Root>> func = () => PreFunc().AsNav();
|
||||
result.PreFunc = func;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -890,15 +890,17 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Nav CUD
|
||||
public InsertNavProvider<T, T> InsertNav<T>(T data) where T : class, new()
|
||||
public InsertNavTaskInit<T, T> InsertNav<T>(T data) where T : class, new()
|
||||
{
|
||||
return InsertNav(new List<T>() { data });
|
||||
}
|
||||
public InsertNavProvider<T, T> InsertNav<T>(List<T> datas) where T : class, new()
|
||||
public InsertNavTaskInit<T, T> InsertNav<T>(List<T> datas) where T : class, new()
|
||||
{
|
||||
var result = new InsertNavProvider<T, T>();
|
||||
result._Roots = datas;
|
||||
result._Context = this;
|
||||
var result = new InsertNavTaskInit<T, T>();
|
||||
var provider = new InsertNavProvider<T, T>();
|
||||
provider._Roots = datas;
|
||||
provider._Context = this;
|
||||
result.insertNavProvider = provider;
|
||||
return result;
|
||||
}
|
||||
public DeleteNavProvider<T, T> DeleteNav<T>(T data)
|
||||
|
@ -678,11 +678,11 @@ namespace SqlSugar
|
||||
{
|
||||
return ScopedContext.Saveable(saveObject);
|
||||
}
|
||||
public InsertNavProvider<T, T> InsertNav<T>(T data) where T : class, new()
|
||||
public InsertNavTaskInit<T, T> InsertNav<T>(T data) where T : class, new()
|
||||
{
|
||||
return ScopedContext.InsertNav(data);
|
||||
}
|
||||
public InsertNavProvider<T, T> InsertNav<T>(List<T> datas) where T : class, new()
|
||||
public InsertNavTaskInit<T, T> InsertNav<T>(List<T> datas) where T : class, new()
|
||||
{
|
||||
return ScopedContext.InsertNav(datas);
|
||||
}
|
||||
|
@ -203,8 +203,8 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Nav CUD
|
||||
InsertNavProvider<T, T> InsertNav<T>(T data) where T : class, new();
|
||||
InsertNavProvider<T, T> InsertNav<T>(List<T> datas) where T : class, new();
|
||||
InsertNavTaskInit<T, T> InsertNav<T>(T data) where T : class, new();
|
||||
InsertNavTaskInit<T, T> InsertNav<T>(List<T> datas) where T : class, new();
|
||||
DeleteNavProvider<T, T> DeleteNav<T>(T data);
|
||||
DeleteNavProvider<T, T> DeleteNav<T>(List<T> datas);
|
||||
UpdateNavProvider<T, T> UpdateNav<T>(T data);
|
||||
|
@ -94,6 +94,7 @@
|
||||
<Compile Include="Abstract\ExecuteNavProvider\InsertNavProviderManyToMany.cs" />
|
||||
<Compile Include="Abstract\ExecuteNavProvider\InsertNavProviderOneToOne.cs" />
|
||||
<Compile Include="Abstract\ExecuteNavProvider\DeleteNavProvider.cs" />
|
||||
<Compile Include="Abstract\ExecuteNavProvider\InsertNavTask.cs" />
|
||||
<Compile Include="Abstract\ExecuteNavProvider\UpdateInsert.cs" />
|
||||
<Compile Include="Abstract\ExecuteNavProvider\InsertNavProvider.cs" />
|
||||
<Compile Include="Abstract\ExpressionableProvider\Expressionable.cs" />
|
||||
|
@ -154,11 +154,11 @@ namespace SqlSugar
|
||||
#region Queryable
|
||||
|
||||
#region Nav CUD
|
||||
public InsertNavProvider<T, T> InsertNav<T>(T data) where T : class, new()
|
||||
public InsertNavTaskInit<T,T> InsertNav<T>(T data) where T : class, new()
|
||||
{
|
||||
return this.Context.InsertNav(data);
|
||||
}
|
||||
public InsertNavProvider<T, T> InsertNav<T>(List<T> datas) where T : class, new()
|
||||
public InsertNavTaskInit<T, T> InsertNav<T>(List<T> datas) where T : class, new()
|
||||
{
|
||||
return this.Context.InsertNav(datas);
|
||||
}
|
||||
|
@ -734,11 +734,11 @@ namespace SqlSugar
|
||||
return ScopedContext.DeleteableWithAttr<T>(deleteObjs);
|
||||
}
|
||||
|
||||
public InsertNavProvider<T, T> InsertNav<T>(T data) where T : class, new()
|
||||
public InsertNavTaskInit<T, T> InsertNav<T>(T data) where T : class, new()
|
||||
{
|
||||
return ScopedContext.InsertNav(data);
|
||||
}
|
||||
public InsertNavProvider<T, T> InsertNav<T>(List<T> datas) where T : class, new()
|
||||
public InsertNavTaskInit<T, T> InsertNav<T>(List<T> datas) where T : class, new()
|
||||
{
|
||||
return ScopedContext.InsertNav(datas);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user