Update .net core project

This commit is contained in:
sunkaixuan
2022-08-31 22:41:50 +08:00
parent 5b5221e7b3
commit a71ed91ac6
7 changed files with 47 additions and 5 deletions

View File

@@ -183,6 +183,14 @@ namespace SqlSugar
#endregion #endregion
#region Transaction #region Transaction
public virtual bool IsAnyTran()
{
return this.Transaction != null;
}
public virtual bool IsNoTran()
{
return this.Transaction == null;
}
public virtual void BeginTran() public virtual void BeginTran()
{ {
CheckConnection(); CheckConnection();

View File

@@ -105,16 +105,32 @@ namespace SqlSugar
{ {
if (isRoot && nav.Navigat.NavigatType != NavigateType.ManyToMany) if (isRoot && nav.Navigat.NavigatType != NavigateType.ManyToMany)
{ {
this._Context.Updateable(_Roots).ExecuteCommand(); UpdateRoot();
} }
else else
{ {
if (_Options != null && _Options.ManyToManyIsUpdateA) if (_Options != null && _Options.ManyToManyIsUpdateA)
{ {
this._Context.Updateable(_Roots).ExecuteCommand(); UpdateRoot();
} }
} }
} }
private void UpdateRoot()
{
if (_Options != null && _Options.RootFunc != null)
{
var updateable = this._Context.Updateable(_Roots);
var exp= _Options.RootFunc as Expression<Action<IUpdateable<Root>>>;
Check.ExceptionEasy(exp == null, "UpdateOptions.RootFunc is error", "UpdateOptions.RootFunc");
var com= exp.Compile();
com(updateable);
updateable.ExecuteCommand();
}
else
{
this._Context.Updateable(_Roots).ExecuteCommand();
}
}
} }
} }

View File

@@ -72,7 +72,19 @@ namespace SqlSugar
var insertData = x.InsertList.Select(it => it.Item).ToList(); var insertData = x.InsertList.Select(it => it.Item).ToList();
var updateData = x.UpdateList.Select(it => it.Item).ToList(); var updateData = x.UpdateList.Select(it => it.Item).ToList();
Check.ExceptionEasy(pkColumn == null && NavColumn == null, $"The entity is invalid", $"实体错误无法使用导航"); Check.ExceptionEasy(pkColumn == null && NavColumn == null, $"The entity is invalid", $"实体错误无法使用导航");
x.AsUpdateable.ExecuteCommand(); if (_Options != null && _Options.CurrentFunc != null)
{
var updateable = x.AsUpdateable;
var exp = _Options.CurrentFunc as Expression<Action<IUpdateable<TChild>>>;
Check.ExceptionEasy(exp == null, "UpdateOptions.CurrentFunc is error", "UpdateOptions.CurrentFunc参数设置错误");
var com = exp.Compile();
com(updateable);
updateable.ExecuteCommand();
}
else
{
x.AsUpdateable.ExecuteCommand();
}
InitData(pkColumn, insertData); InitData(pkColumn, insertData);
if (_NavigateType == NavigateType.OneToMany) if (_NavigateType == NavigateType.OneToMany)
{ {

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Expressions;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -16,6 +17,8 @@ namespace SqlSugar
public bool ManyToManyIsUpdateA { get; set; } public bool ManyToManyIsUpdateA { get; set; }
public bool ManyToManyIsUpdateB { get; set; } public bool ManyToManyIsUpdateB { get; set; }
public bool OneToManyDeleteAll { get; set; } public bool OneToManyDeleteAll { get; set; }
public Expression RootFunc { get; set; }
public Expression CurrentFunc { get; set; }
} }
public class InsertNavOptions public class InsertNavOptions

View File

@@ -215,6 +215,7 @@ namespace SqlSugar
+ Context.ParameterIndex; + Context.ParameterIndex;
if (value.ObjToString() != "NULL" && !parameter.ValueIsNull) if (value.ObjToString() != "NULL" && !parameter.ValueIsNull)
{ {
value = this.Context.TableEnumIsString == true ? value.ToString() : value;
this.Context.Parameters.Add(new SugarParameter(appendValue, value)); this.Context.Parameters.Add(new SugarParameter(appendValue, value));
} }
else else

View File

@@ -20,6 +20,8 @@ namespace SqlSugar
SqlSugarProvider Context { get; set; } SqlSugarProvider Context { get; set; }
void ExecuteBefore(string sql, SugarParameter[] pars); void ExecuteBefore(string sql, SugarParameter[] pars);
void ExecuteAfter(string sql, SugarParameter[] pars); void ExecuteAfter(string sql, SugarParameter[] pars);
bool IsAnyTran();
bool IsNoTran();
bool IsEnableLogEvent{get;set;} bool IsEnableLogEvent{get;set;}
StackTraceInfo SqlStackTrace { get; } StackTraceInfo SqlStackTrace { get; }
IDataParameterCollection DataReaderParameters { get; set; } IDataParameterCollection DataReaderParameters { get; set; }

View File

@@ -39,7 +39,7 @@ namespace SqlSugar
{ {
this.Tenant.RollbackTran(); this.Tenant.RollbackTran();
} }
if (IsClose == false) if (this.Db.Ado.Transaction==null&&IsClose == false)
{ {
this.Db.Close(); this.Db.Close();
} }
@@ -81,7 +81,7 @@ namespace SqlSugar
this.Tenant.CommitTran(); this.Tenant.CommitTran();
IsCommit = true; IsCommit = true;
} }
if (this.IsClose == false) if (this.Db.Ado.Transaction==null&&this.IsClose == false)
{ {
this.Db.Close(); this.Db.Close();
IsClose = true; IsClose = true;