mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 10:08:19 +08:00
Update .net core project
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public partial class DeleteNavProvider<Root, T> where T : class, new() where Root : class, new()
|
||||
{
|
||||
private void DeleteManyToMany<TChild>(string name, EntityColumnInfo nav) where TChild : class, new()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public partial class DeleteNavProvider<Root, T> where T : class, new() where Root : class, new()
|
||||
{
|
||||
|
||||
private void DeleteOneToMany<TChild>(string name, EntityColumnInfo nav) where TChild : class, new()
|
||||
{
|
||||
var parentEntity = _ParentEntity;
|
||||
var prentList = _ParentList.Cast<T>().ToList();
|
||||
var parentNavigateProperty = parentEntity.Columns.FirstOrDefault(it => it.PropertyName == name);
|
||||
var thisEntity = this._Context.EntityMaintenance.GetEntityInfo<TChild>();
|
||||
var thisPkColumn = GetPkColumnByNav(thisEntity, nav);
|
||||
var thisFkColumn = GetFKColumnByNav(thisEntity, nav);
|
||||
EntityColumnInfo parentPkColumn = GetParentPkColumn();
|
||||
EntityColumnInfo parentNavColumn = GetParentPkNavColumn(nav);
|
||||
if (parentNavColumn != null)
|
||||
{
|
||||
parentPkColumn = parentNavColumn;
|
||||
}
|
||||
|
||||
if (!_IsDeletedParant)
|
||||
SetContext(() => this._Context.Deleteable(prentList).ExecuteCommand());
|
||||
|
||||
var ids = _ParentList.Select(it => parentPkColumn.PropertyInfo.GetValue(it)).ToList();
|
||||
var childList = this._Context.Queryable<TChild>().In(thisFkColumn.DbColumnName, ids).ToList();
|
||||
|
||||
this._ParentList = childList.Cast<object>().ToList();
|
||||
this._ParentPkColumn = thisPkColumn;
|
||||
this._IsDeletedParant = true;
|
||||
|
||||
SetContext(() => this._Context.Deleteable(childList).ExecuteCommand());
|
||||
}
|
||||
|
||||
private void SetContext(Action action)
|
||||
{
|
||||
var key = "_DeleteNavTask";
|
||||
if (this._Context.TempItems == null)
|
||||
{
|
||||
this._Context.TempItems = new Dictionary<string, object>();
|
||||
}
|
||||
if (!this._Context.TempItems.ContainsKey(key))
|
||||
{
|
||||
this._Context.TempItems.Add(key, null);
|
||||
}
|
||||
var oldTask = this._Context.TempItems[key];
|
||||
var newTask = new List<Action>();
|
||||
if (oldTask != null)
|
||||
{
|
||||
newTask = (List<Action>)oldTask;
|
||||
}
|
||||
newTask.Add(action);
|
||||
this._Context.TempItems[key] = newTask;
|
||||
}
|
||||
|
||||
private EntityColumnInfo GetParentPkColumn()
|
||||
{
|
||||
EntityColumnInfo parentPkColumn = _ParentPkColumn;
|
||||
if (_ParentPkColumn == null)
|
||||
{
|
||||
parentPkColumn = _ParentPkColumn = this._ParentEntity.Columns.FirstOrDefault(it => it.IsPrimarykey);
|
||||
}
|
||||
return parentPkColumn;
|
||||
}
|
||||
private EntityColumnInfo GetParentPkNavColumn(EntityColumnInfo nav)
|
||||
{
|
||||
EntityColumnInfo result = null;
|
||||
if (nav.Navigat.Name2.HasValue())
|
||||
{
|
||||
result = _ParentPkColumn = this._ParentEntity.Columns.FirstOrDefault(it => it.PropertyName == nav.Navigat.Name2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private EntityColumnInfo GetPkColumnByNav(EntityInfo entity, EntityColumnInfo nav)
|
||||
{
|
||||
var pkColumn = entity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
|
||||
if (nav.Navigat.Name2.HasValue())
|
||||
{
|
||||
pkColumn = entity.Columns.FirstOrDefault(it => it.PropertyName == nav.Navigat.Name2);
|
||||
}
|
||||
return pkColumn;
|
||||
}
|
||||
private EntityColumnInfo GetFKColumnByNav(EntityInfo entity, EntityColumnInfo nav)
|
||||
{
|
||||
var fkColumn = entity.Columns.FirstOrDefault(it => it.PropertyName == nav.Navigat.Name);
|
||||
return fkColumn;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public partial class DeleteNavProvider<Root, T> where T : class, new() where Root : class, new()
|
||||
{
|
||||
private void DeleteOneToOne<TChild>(string name, EntityColumnInfo nav) where TChild : class, new()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -7,35 +7,104 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class DeleteNavProvider<Root,T>
|
||||
public partial class DeleteNavProvider<Root, T> where T : class, new() where Root : class, new()
|
||||
{
|
||||
public List<Root> _Roots { get; set; }
|
||||
public List<object> _ParentList { get; set; }
|
||||
public List<object> _RootList { get; set; }
|
||||
public EntityInfo _ParentEntity { get; set; }
|
||||
public EntityColumnInfo _ParentPkColumn { get; set; }
|
||||
public SqlSugarProvider _Context { get; set; }
|
||||
public bool _IsDeletedParant { get; set; }
|
||||
|
||||
public List<Root> Roots { get; set; }
|
||||
public SqlSugarProvider Context { get; internal set; }
|
||||
public DeleteNavProvider<Root, TChild> ThenInclude< TChild>(Expression<Func<T, TChild>> expression)
|
||||
where TChild : class, new()
|
||||
{
|
||||
InitParentList();
|
||||
var name = ExpressionTool.GetMemberName(expression);
|
||||
var nav = this._ParentEntity.Columns.FirstOrDefault(x => x.PropertyName == name);
|
||||
if (nav.Navigat == null)
|
||||
{
|
||||
Check.ExceptionEasy($"{name} no navigate attribute", $"{this._ParentEntity.EntityName}的属性{name}没有导航属性");
|
||||
}
|
||||
if (nav.Navigat.NavigatType == NavigateType.OneToOne || nav.Navigat.NavigatType == NavigateType.ManyToOne)
|
||||
{
|
||||
DeleteOneToOne<TChild>(name, nav);
|
||||
}
|
||||
else if (nav.Navigat.NavigatType == NavigateType.OneToMany)
|
||||
{
|
||||
DeleteOneToMany<TChild>(name, nav);
|
||||
}
|
||||
else
|
||||
{
|
||||
DeleteManyToMany<TChild>(name, nav);
|
||||
}
|
||||
return GetResult<TChild>();
|
||||
}
|
||||
|
||||
public DeleteNavProvider<Root,TChild> ThenInclude<TChild>(Expression<Func<T,TChild>> expression)
|
||||
{
|
||||
throw new Exception("开发中7月15号之前上线");
|
||||
}
|
||||
public DeleteNavProvider<Root, TChild> Include<TChild>(Expression<Func<T, TChild>> expression)
|
||||
{
|
||||
throw new Exception("开发中7月15号之前上线");
|
||||
}
|
||||
public DeleteNavProvider<Root, TChild> ThenInclude<TChild>(Expression<Func<T, List<TChild>>> expression)
|
||||
where TChild : class, new()
|
||||
{
|
||||
throw new Exception("开发中7月15号之前上线");
|
||||
InitParentList();
|
||||
var name = ExpressionTool.GetMemberName(expression);
|
||||
var nav = this._ParentEntity.Columns.FirstOrDefault(x => x.PropertyName == name);
|
||||
if (nav.Navigat == null)
|
||||
{
|
||||
Check.ExceptionEasy($"{name} no navigate attribute", $"{this._ParentEntity.EntityName}的属性{name}没有导航属性");
|
||||
}
|
||||
if (nav.Navigat.NavigatType == NavigateType.OneToOne || nav.Navigat.NavigatType == NavigateType.ManyToOne)
|
||||
{
|
||||
DeleteOneToOne<TChild>(name, nav);
|
||||
}
|
||||
else if (nav.Navigat.NavigatType == NavigateType.OneToMany)
|
||||
{
|
||||
DeleteOneToMany<TChild>(name, nav);
|
||||
}
|
||||
else
|
||||
{
|
||||
DeleteManyToMany<TChild>(name, nav);
|
||||
}
|
||||
return GetResult<TChild>();
|
||||
}
|
||||
public DeleteNavProvider<Root, TChild> Include<TChild>(Expression<Func<T, List<TChild>>> expression)
|
||||
private DeleteNavProvider<Root, TChild> GetResult<TChild>() where TChild : class, new()
|
||||
{
|
||||
throw new Exception("开发中7月15号之前上线");
|
||||
return new DeleteNavProvider<Root, TChild>()
|
||||
{
|
||||
_Context = this._Context,
|
||||
_ParentEntity = this._ParentEntity,
|
||||
_ParentList = this._ParentList,
|
||||
_Roots = this._Roots,
|
||||
_ParentPkColumn = this._ParentPkColumn,
|
||||
_RootList = this._RootList,
|
||||
_IsDeletedParant=this._IsDeletedParant
|
||||
};
|
||||
}
|
||||
private DeleteNavProvider<Root,Root> AsNav()
|
||||
public DeleteNavProvider<Root, Root> AsNav()
|
||||
{
|
||||
throw new Exception("开发中7月15号之前上线");
|
||||
return new DeleteNavProvider<Root, Root>
|
||||
{
|
||||
_Context = _Context,
|
||||
_ParentEntity = null,
|
||||
_ParentList = null,
|
||||
_Roots = _Roots,
|
||||
_IsDeletedParant = this._IsDeletedParant,
|
||||
_ParentPkColumn = this._Context.EntityMaintenance.GetEntityInfo<Root>().Columns.First(it => it.IsPrimarykey)
|
||||
};
|
||||
}
|
||||
public bool ExecuteCommand()
|
||||
private void InitParentList()
|
||||
{
|
||||
return true;
|
||||
this._ParentEntity = this._Context.EntityMaintenance.GetEntityInfo<T>();
|
||||
if (_RootList == null)
|
||||
{
|
||||
_RootList = _ParentList = _Roots.Cast<object>().ToList();
|
||||
}
|
||||
else if (_ParentList == null)
|
||||
{
|
||||
_ParentList = _RootList;
|
||||
var pkColumn = this._Context.EntityMaintenance.GetEntityInfo<T>().Columns.FirstOrDefault(it => it.IsPrimarykey);
|
||||
this._ParentPkColumn = pkColumn;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class DeleteNavTaskInit<Root,T> where T : class, new() where Root : class, new()
|
||||
{
|
||||
internal List<T> Roots { get; set; }
|
||||
internal SqlSugarProvider Context { get; set; }
|
||||
internal DeleteNavProvider<Root, Root> deleteNavProvider { get; set; }
|
||||
|
||||
public DeleteNavTask<Root, TChild> Include<TChild>(Expression<Func<Root, TChild>> expression) where TChild : class, new()
|
||||
{
|
||||
this.Context = deleteNavProvider._Context;
|
||||
DeleteNavTask<Root, TChild> result = new DeleteNavTask<Root, TChild>();
|
||||
Func<DeleteNavProvider<Root, TChild>> func = () => deleteNavProvider.ThenInclude(expression);
|
||||
result.PreFunc = func;
|
||||
result.Context = this.Context;
|
||||
return result;
|
||||
}
|
||||
public DeleteNavTask<Root, TChild> Include<TChild>(Expression<Func<Root, List<TChild>>> expression) where TChild : class, new()
|
||||
{
|
||||
this.Context = deleteNavProvider._Context;
|
||||
DeleteNavTask<Root, TChild> result = new DeleteNavTask<Root, TChild>();
|
||||
Func<DeleteNavProvider<Root, TChild>> func = () => deleteNavProvider.ThenInclude(expression);
|
||||
result.PreFunc = func;
|
||||
result.Context = this.Context;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public class DeleteNavTask<Root, T> where T : class, new() where Root : class, new()
|
||||
{
|
||||
public SqlSugarProvider Context { get; set; }
|
||||
public Func<DeleteNavProvider<Root, T>> PreFunc { get; set; }
|
||||
public DeleteNavTask<Root, TChild> ThenInclude<TChild>(Expression<Func<T, TChild>> expression) where TChild : class, new()
|
||||
{
|
||||
DeleteNavTask<Root, TChild> result = new DeleteNavTask<Root, TChild>();
|
||||
Func<DeleteNavProvider<Root, TChild>> func = () => PreFunc().ThenInclude(expression);
|
||||
result.PreFunc = func;
|
||||
result.Context = this.Context;
|
||||
return result;
|
||||
}
|
||||
public DeleteNavTask<Root, TChild> ThenInclude<TChild>(Expression<Func<T, List<TChild>>> expression) where TChild : class, new()
|
||||
{
|
||||
DeleteNavTask<Root, TChild> result = new DeleteNavTask<Root, TChild>();
|
||||
Func<DeleteNavProvider<Root, TChild>> func = () => PreFunc().ThenInclude(expression);
|
||||
result.PreFunc = func;
|
||||
result.Context = this.Context;
|
||||
return result;
|
||||
}
|
||||
public DeleteNavTask<Root, TChild> Include<TChild>(Expression<Func<Root, TChild>> expression) where TChild : class, new()
|
||||
{
|
||||
return AsNav().ThenInclude(expression);
|
||||
}
|
||||
public DeleteNavTask<Root, TChild> Include<TChild>(Expression<Func<Root, List<TChild>>> expression) where TChild : class, new()
|
||||
{
|
||||
return AsNav().ThenInclude(expression);
|
||||
}
|
||||
public bool ExecuteCommand()
|
||||
{
|
||||
PreFunc();
|
||||
|
||||
var hasTran = this.Context.Ado.Transaction != null;
|
||||
if (hasTran)
|
||||
{
|
||||
ExecTasks();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Context.Ado.UseTran(() =>
|
||||
{
|
||||
ExecTasks();
|
||||
|
||||
}, ex => throw ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public async Task<bool> ExecuteCommandAsync()
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
ExecuteCommand();
|
||||
await Task.Delay(0);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
private DeleteNavTask<Root, Root> AsNav()
|
||||
{
|
||||
DeleteNavTask<Root, Root> result = new DeleteNavTask<Root, Root>();
|
||||
Func<DeleteNavProvider<Root, Root>> func = () => PreFunc().AsNav();
|
||||
result.PreFunc = func;
|
||||
result.Context = this.Context;
|
||||
return result;
|
||||
}
|
||||
private void ExecTasks()
|
||||
{
|
||||
var tasks=(List<Action>)this.Context.TempItems["_DeleteNavTask"];
|
||||
tasks.Reverse();
|
||||
foreach (var task in tasks)
|
||||
{
|
||||
task();
|
||||
}
|
||||
this.Context.TempItems.Remove("_DeleteNavTask");
|
||||
}
|
||||
}
|
||||
}
|
@@ -903,17 +903,22 @@ namespace SqlSugar
|
||||
result.insertNavProvider = provider;
|
||||
return result;
|
||||
}
|
||||
public DeleteNavProvider<T, T> DeleteNav<T>(T data)
|
||||
public DeleteNavTaskInit<T, T> DeleteNav<T>(T data) where T : class, new()
|
||||
{
|
||||
return DeleteNav(new List<T>() { data });
|
||||
}
|
||||
public DeleteNavProvider<T, T> DeleteNav<T>(List<T> datas)
|
||||
public DeleteNavTaskInit<T, T> DeleteNav<T>(List<T> datas) where T : class, new()
|
||||
{
|
||||
var result = new DeleteNavProvider<T, T>();
|
||||
result.Roots = datas;
|
||||
result.Context = this;
|
||||
var result = new DeleteNavTaskInit<T, T>();
|
||||
result.deleteNavProvider = new DeleteNavProvider<T, T>();
|
||||
result.deleteNavProvider._Roots = datas;
|
||||
result.deleteNavProvider._Context = this;
|
||||
return result;
|
||||
}
|
||||
public DeleteNavTaskInit<T, T> DeleteNav<T>(Expression<Func<T, bool>> whereExpression) where T : class, new()
|
||||
{
|
||||
return DeleteNav(this.Queryable<T>().Where(whereExpression).ToList());
|
||||
}
|
||||
public UpdateNavProvider<T, T> UpdateNav<T>(T data)
|
||||
{
|
||||
return UpdateNav(new List<T>() { data });
|
||||
|
@@ -686,14 +686,18 @@ namespace SqlSugar
|
||||
{
|
||||
return ScopedContext.InsertNav(datas);
|
||||
}
|
||||
public DeleteNavProvider<T, T> DeleteNav<T>(T data)
|
||||
public DeleteNavTaskInit<T, T> DeleteNav<T>(T data) where T : class, new()
|
||||
{
|
||||
return ScopedContext.DeleteNav(data);
|
||||
}
|
||||
public DeleteNavProvider<T, T> DeleteNav<T>(List<T> datas)
|
||||
public DeleteNavTaskInit<T, T> DeleteNav<T>(List<T> datas) where T : class, new()
|
||||
{
|
||||
return ScopedContext.DeleteNav(datas);
|
||||
}
|
||||
public DeleteNavTaskInit<T, T> DeleteNav<T>(Expression<Func<T, bool>> whereExpression) where T : class, new()
|
||||
{
|
||||
return ScopedContext.DeleteNav(whereExpression);
|
||||
}
|
||||
public UpdateNavProvider<T, T> UpdateNav<T>(T data)
|
||||
{
|
||||
return ScopedContext.UpdateNav(data);
|
||||
|
@@ -205,8 +205,9 @@ namespace SqlSugar
|
||||
#region Nav CUD
|
||||
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);
|
||||
DeleteNavTaskInit<T, T> DeleteNav<T>(T data) where T : class, new();
|
||||
DeleteNavTaskInit<T, T> DeleteNav<T>(List<T> datas) where T : class, new();
|
||||
DeleteNavTaskInit<T, T> DeleteNav<T>(Expression<Func<T,bool>> whereExpression) where T : class, new();
|
||||
UpdateNavProvider<T, T> UpdateNav<T>(T data);
|
||||
UpdateNavProvider<T, T> UpdateNav<T>(List<T> datas);
|
||||
#endregion
|
||||
|
@@ -162,14 +162,18 @@ namespace SqlSugar
|
||||
{
|
||||
return this.Context.InsertNav(datas);
|
||||
}
|
||||
public DeleteNavProvider<T, T> DeleteNav<T>(T data)
|
||||
public DeleteNavTaskInit<T, T> DeleteNav<T>(T data) where T : class, new()
|
||||
{
|
||||
return this.Context.DeleteNav(data);
|
||||
}
|
||||
public DeleteNavProvider<T, T> DeleteNav<T>(List<T> datas)
|
||||
public DeleteNavTaskInit<T, T> DeleteNav<T>(List<T> datas) where T : class, new()
|
||||
{
|
||||
return this.Context.DeleteNav(datas);
|
||||
}
|
||||
public DeleteNavTaskInit<T, T> DeleteNav<T>(Expression<Func<T, bool>> whereExpression) where T : class, new()
|
||||
{
|
||||
return this.Context.DeleteNav(whereExpression);
|
||||
}
|
||||
public UpdateNavProvider<T, T> UpdateNav<T>(T data)
|
||||
{
|
||||
return this.Context.UpdateNav(data);
|
||||
|
@@ -742,14 +742,18 @@ namespace SqlSugar
|
||||
{
|
||||
return ScopedContext.InsertNav(datas);
|
||||
}
|
||||
public DeleteNavProvider<T, T> DeleteNav<T>(T data)
|
||||
public DeleteNavTaskInit<T, T> DeleteNav<T>(T data) where T : class, new()
|
||||
{
|
||||
return ScopedContext.DeleteNav(data);
|
||||
}
|
||||
public DeleteNavProvider<T, T> DeleteNav<T>(List<T> datas)
|
||||
public DeleteNavTaskInit<T, T> DeleteNav<T>(List<T> datas) where T : class, new()
|
||||
{
|
||||
return ScopedContext.DeleteNav(datas);
|
||||
}
|
||||
public DeleteNavTaskInit<T, T> DeleteNav<T>(Expression<Func<T, bool>> whereExpression) where T : class, new()
|
||||
{
|
||||
return ScopedContext.DeleteNav(whereExpression);
|
||||
}
|
||||
public UpdateNavProvider<T, T> UpdateNav<T>(T data)
|
||||
{
|
||||
return ScopedContext.UpdateNav(data);
|
||||
|
Reference in New Issue
Block a user