Browse Source

Update core

pull/20/head
sunkaixuan 2 years ago
parent
commit
6675e17698
  1. 89
      Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/InsertNavTask.cs
  2. 12
      Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs
  3. 4
      Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarScopeProvider.cs
  4. 4
      Src/Asp.NetCore2/SqlSugar/Interface/ISqlSugarClient.cs
  5. 4
      Src/Asp.NetCore2/SqlSugar/SqlSugarClient.cs
  6. 4
      Src/Asp.NetCore2/SqlSugar/SqlSugarScope.cs

89
Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/InsertNavTask.cs

@ -0,0 +1,89 @@
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;
result.Context = this.Context;
return result;
}
}
}

12
Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs

@ -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)

4
Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarScopeProvider.cs

@ -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);
}

4
Src/Asp.NetCore2/SqlSugar/Interface/ISqlSugarClient.cs

@ -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);

4
Src/Asp.NetCore2/SqlSugar/SqlSugarClient.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);
}

4
Src/Asp.NetCore2/SqlSugar/SqlSugarScope.cs

@ -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…
Cancel
Save