Browse Source

Update .net core project

pull/20/head
sunkaixuan 2 years ago
parent
commit
195a649eb7
  1. 52
      Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/DeleteNavManyToMany.cs
  2. 22
      Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/DeleteNavOneToOne.cs
  3. 1
      Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/DeleteNavProvider.cs
  4. 18
      Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/DeleteNavTask.cs
  5. 14
      Src/Asp.NetCore2/SqlSugar/Entities/DeleteNavOptions.cs
  6. 8
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs
  7. 1
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs
  8. 6
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs
  9. 2
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

52
Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/DeleteNavManyToMany.cs

@ -10,8 +10,60 @@ namespace SqlSugar
{
private void DeleteManyToMany<TChild>(string name, EntityColumnInfo nav) where TChild : class, new()
{
var parentEntity = _ParentEntity;
var parentList = _ParentList.Cast<T>().ToList();
var parentPkColumn = parentEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
var parentNavigateProperty = parentEntity.Columns.FirstOrDefault(it => it.PropertyName == name);
var thisEntity = this._Context.EntityMaintenance.GetEntityInfo<TChild>();
var thisPkColumn = thisEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
Check.Exception(thisPkColumn == null, $"{thisPkColumn.EntityName} need primary key", $"{thisPkColumn.EntityName}需要主键");
Check.Exception(parentPkColumn == null, $"{parentPkColumn.EntityName} need primary key", $"{parentPkColumn.EntityName}需要主键");
var mappingType = parentNavigateProperty.Navigat.MappingType;
var mappingEntity = this._Context.EntityMaintenance.GetEntityInfo(mappingType);
var mappingA = mappingEntity.Columns.FirstOrDefault(x => x.PropertyName == parentNavigateProperty.Navigat.MappingAId);
var mappingB = mappingEntity.Columns.FirstOrDefault(x => x.PropertyName == parentNavigateProperty.Navigat.MappingBId);
var mappingPk = mappingEntity.Columns
.Where(it => it.PropertyName != mappingA.PropertyName)
.Where(it => it.PropertyName != mappingB.PropertyName)
.Where(it => it.IsPrimarykey && !it.IsIdentity && it.OracleSequenceName.IsNullOrEmpty()).FirstOrDefault();
if (IsDeleteA())
{
if (!_IsDeletedParant)
SetContext(() => this._Context.Deleteable(parentList).ExecuteCommand());
}
var aids = _ParentList.Select(it => parentPkColumn.PropertyInfo.GetValue(it)).ToList();
var bids = _Context.Queryable<object>().AS(mappingEntity.DbTableName).In(mappingA.DbColumnName, aids)
.Select(mappingB.DbColumnName).ToDataTable()
.Rows.Cast<System.Data.DataRow>().Select(it => it[0]).ToList();
var childList = this._Context.Queryable<TChild>().In(thisPkColumn.DbColumnName, bids).ToList();
if (IsDeleteB())
{
SetContext(() => _Context.Deleteable(childList).ExecuteCommand());
}
this._ParentList = childList.Cast<object>().ToList();
this._ParentPkColumn = thisPkColumn;
this._IsDeletedParant = true;
SetContext(() => _Context.Deleteable<object>().AS(mappingEntity.DbTableName).In(
mappingA.DbColumnName, aids
).ExecuteCommand());
}
private bool IsDeleteA()
{
return deleteNavOptions != null && deleteNavOptions.ManyToMayIsDeleteA;
}
private bool IsDeleteB()
{
return deleteNavOptions != null && deleteNavOptions.ManyToMayIsDeleteB;
}
}
}

22
Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/DeleteNavOneToOne.cs

@ -10,7 +10,27 @@ namespace SqlSugar
{
private void DeleteOneToOne<TChild>(string name, EntityColumnInfo nav) where TChild : class, new()
{
var parentEntity = _ParentEntity;
var parentList = _ParentList.Cast<T>().ToList();
var parentColumn = parentEntity.Columns.FirstOrDefault(it => it.PropertyName == nav.Navigat.Name);
var parentPkColumn = parentEntity.Columns.FirstOrDefault(it => it.IsPrimarykey);
var thisEntity = this._Context.EntityMaintenance.GetEntityInfo<TChild>();
EntityColumnInfo thisPkColumn = GetPkColumnByNav(thisEntity, nav);
Check.Exception(thisPkColumn == null, $" Navigate {parentEntity.EntityName} : {name} is error ", $"导航实体 {parentEntity.EntityName} 属性 {name} 配置错误");
if (!_IsDeletedParant)
SetContext(() => this._Context.Deleteable(parentList).ExecuteCommand());
var ids = _ParentList.Select(it => parentColumn.PropertyInfo.GetValue(it)).ToList();
List<TChild> childList = this._Context.Queryable<TChild>().In(thisPkColumn.DbColumnName, ids).ToList();
this._ParentList = childList.Cast<object>().ToList();
this._ParentPkColumn = thisPkColumn;
this._IsDeletedParant = true;
SetContext(() => this._Context.Deleteable(childList).ExecuteCommand());
}
}

1
Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/DeleteNavProvider.cs

@ -9,6 +9,7 @@ namespace SqlSugar
{
public partial class DeleteNavProvider<Root, T> where T : class, new() where Root : class, new()
{
internal DeleteNavOptions deleteNavOptions;
public List<Root> _Roots { get; set; }
public List<object> _ParentList { get; set; }
public List<object> _RootList { get; set; }

18
Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/DeleteNavTask.cs

@ -31,6 +31,12 @@ namespace SqlSugar
result.Context = this.Context;
return result;
}
public DeleteNavTask<Root, TChild> Include<TChild>(Expression<Func<Root, List<TChild>>> expression,DeleteNavOptions deleteNavOptions) where TChild : class, new()
{
var result= Include(expression);
deleteNavProvider.deleteNavOptions = deleteNavOptions;
return result;
}
}
public class DeleteNavTask<Root, T> where T : class, new() where Root : class, new()
{
@ -52,6 +58,18 @@ namespace SqlSugar
result.Context = this.Context;
return result;
}
public DeleteNavTask<Root, TChild> ThenInclude<TChild>(Expression<Func<T, List<TChild>>> expression,DeleteNavOptions deleteNavOptions) where TChild : class, new()
{
DeleteNavTask<Root, TChild> result = new DeleteNavTask<Root, TChild>();
Func<DeleteNavProvider<Root, TChild>> func = () => {
var dev = PreFunc();
dev.deleteNavOptions = deleteNavOptions;
return dev.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);

14
Src/Asp.NetCore2/SqlSugar/Entities/DeleteNavOptions.cs

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
public class DeleteNavOptions
{
public bool ManyToMayIsDeleteA { get; set; }
public bool ManyToMayIsDeleteB { get; set; }
}
}

8
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs

@ -544,5 +544,13 @@ namespace SqlSugar
{
return model.Args[0].MemberName + " DESC ";
}
public virtual string Stuff(MethodCallExpressionModel model)
{
var parameter1 = model.Args[0];
var parameter2 = model.Args[1];
var parameter3 = model.Args[2];
var parameter4 = model.Args[3];
return $" STUFF ({parameter1.MemberName}, {parameter2.MemberName}, {parameter3.MemberName}, {parameter4.MemberName}) ";
}
}
}

1
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs

@ -85,5 +85,6 @@ namespace SqlSugar
string LessThanOrEqual(MethodCallExpressionModel model);
string Asc(MethodCallExpressionModel model);
string Desc(MethodCallExpressionModel model);
string Stuff(MethodCallExpressionModel model);
}
}

6
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs

@ -25,6 +25,12 @@ namespace SqlSugar
{
throw new NotSupportedException("Can only be used in expressions");
}
public static string Stuff(string sourceString, int start, int length, string AddString)
{
throw new NotSupportedException("Can only be used in expressions");
}
public static bool GreaterThanOrEqual(object thisValue, object gtValue)
{
throw new NotSupportedException("Can only be used in expressions");

2
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

@ -998,6 +998,8 @@ namespace SqlSugar
return this.Context.DbMehtods.Asc(model);
case "Desc":
return this.Context.DbMehtods.Desc(model);
case "Stuff":
return this.Context.DbMehtods.Stuff(model);
default:
break;
}

Loading…
Cancel
Save