mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-23 04:23:47 +08:00
Update Core
This commit is contained in:
@@ -9,5 +9,7 @@ namespace OrmTest
|
||||
public class Config
|
||||
{
|
||||
public static string ConnectionString = "server=.;uid=sa;pwd=sasa;database=SqlSugar4XTest";
|
||||
public static string ConnectionString2 = "server=.;uid=sa;pwd=sasa;database=SQLSUGAR4XTEST";
|
||||
public static string ConnectionString3 = "server=.;uid=sa;pwd=sasa;database=sqlsugar4xtest";
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,44 @@
|
||||
using OrmTest.Demo;
|
||||
using OrmTest.Models;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OrmTest.Demo
|
||||
{
|
||||
public class MasterSlave : DemoBase
|
||||
{
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
var db = GetMasterSlaveInstance();
|
||||
var list = db.Insertable(new Student() { Name="aa" }).ExecuteCommand(); // ConnectionString2 or ConnectionString3
|
||||
}
|
||||
//db.Insertable(new Student() { Name = "masterTest" }).ExecuteCommand();// Config.ConnectionString
|
||||
}
|
||||
|
||||
public static SqlSugarClient GetMasterSlaveInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
ConnectionString = Config.ConnectionString,
|
||||
DbType = DbType.SqlServer,
|
||||
IsAutoCloseConnection = true,
|
||||
SlaveConnectionConfigs = new List<SlaveConnectionConfig>() {
|
||||
new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 } ,
|
||||
new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 }
|
||||
}
|
||||
});
|
||||
db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(db.Ado.Connection.ConnectionString);
|
||||
};
|
||||
return db;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,87 @@
|
||||
using OrmTest.Models;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OrmTest.Demo
|
||||
{
|
||||
public class SharedConnection : DemoBase
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
StudentDal studentDal = new StudentDal();
|
||||
SchoolDal schoolDal = new SchoolDal();
|
||||
|
||||
try
|
||||
{
|
||||
studentDal.BeginTran();
|
||||
|
||||
Console.WriteLine("school Count:"+ schoolDal.GetSchoolCount());//0
|
||||
|
||||
studentDal.AddStudent(new Student() { Name = "StudentTest" });
|
||||
schoolDal.AddSchool(new School() { Name = "SchoolTest" });//1
|
||||
|
||||
Console.WriteLine("school Count:" + schoolDal.GetSchoolCount());
|
||||
|
||||
throw new Exception("error");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
studentDal.RollbackTran();
|
||||
Console.WriteLine("school Count:" + schoolDal.GetSchoolCount());//0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public class StudentDal : BaseDao
|
||||
{
|
||||
public void AddStudent(Student sudent)
|
||||
{
|
||||
db.Insertable(sudent).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
public class SchoolDal : BaseDao
|
||||
{
|
||||
public void AddSchool(School school)
|
||||
{
|
||||
db.Insertable(school).ExecuteCommand();
|
||||
}
|
||||
public int GetSchoolCount()
|
||||
{
|
||||
return db.Queryable<School>().Count();
|
||||
}
|
||||
}
|
||||
|
||||
public class BaseDao
|
||||
{
|
||||
|
||||
public SqlSugar.SqlSugarClient db { get { return GetInstance(); } }
|
||||
public void BeginTran()
|
||||
{
|
||||
db.Ado.BeginTran();
|
||||
}
|
||||
public void CommitTran()
|
||||
{
|
||||
db.Ado.CommitTran();
|
||||
}
|
||||
public void RollbackTran()
|
||||
{
|
||||
db.Ado.RollbackTran();
|
||||
}
|
||||
public SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(
|
||||
new ConnectionConfig() {
|
||||
ConnectionString = Config.ConnectionString,
|
||||
DbType = DbType.SqlServer,
|
||||
IsAutoCloseConnection = false,
|
||||
IsShardSameThread= true /*Shard Same Thread*/
|
||||
});
|
||||
|
||||
return db;
|
||||
}
|
||||
}
|
||||
}
|
@@ -37,6 +37,8 @@ namespace SqlSeverTest
|
||||
OrmTest.Demo.Filter.Init();
|
||||
OrmTest.Demo.ComplexModel.Init();
|
||||
OrmTest.Demo.CodeFirst.Init();
|
||||
OrmTest.Demo.MasterSlave.Init();
|
||||
OrmTest.Demo.SharedConnection.Init();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -75,7 +75,7 @@ namespace SqlSugar
|
||||
{
|
||||
this.Connection.Close();
|
||||
}
|
||||
if (this.IsMasterSlaveSeparation)
|
||||
if (this.IsMasterSlaveSeparation && this.SlaveConnections.HasValue())
|
||||
{
|
||||
foreach (var slaveConnection in this.SlaveConnections)
|
||||
{
|
||||
@@ -263,7 +263,7 @@ namespace SqlSugar
|
||||
if (this.IsClearParameters)
|
||||
sqlCommand.Parameters.Clear();
|
||||
ExecuteAfter(sql, parameters);
|
||||
SetConnectionEnd();
|
||||
SetConnectionEnd(sql);
|
||||
return count;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -293,7 +293,7 @@ namespace SqlSugar
|
||||
if (this.IsClearParameters)
|
||||
sqlCommand.Parameters.Clear();
|
||||
ExecuteAfter(sql, parameters);
|
||||
SetConnectionEnd();
|
||||
SetConnectionEnd(sql);
|
||||
return sqlDataReader;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -319,7 +319,7 @@ namespace SqlSugar
|
||||
if (this.IsClearParameters)
|
||||
sqlCommand.Parameters.Clear();
|
||||
ExecuteAfter(sql, parameters);
|
||||
SetConnectionEnd();
|
||||
SetConnectionEnd(sql);
|
||||
return ds;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -347,7 +347,7 @@ namespace SqlSugar
|
||||
if (this.IsClearParameters)
|
||||
sqlCommand.Parameters.Clear();
|
||||
ExecuteAfter(sql, parameters);
|
||||
SetConnectionEnd();
|
||||
SetConnectionEnd(sql);
|
||||
return scalar;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -719,9 +719,9 @@ namespace SqlSugar
|
||||
return result.Count() == 0;
|
||||
}
|
||||
|
||||
private void SetConnectionEnd()
|
||||
private void SetConnectionEnd(string sql)
|
||||
{
|
||||
if (this.IsMasterSlaveSeparation)
|
||||
if (this.IsMasterSlaveSeparation && IsRead(sql))
|
||||
{
|
||||
this.Connection = this.MasterConnection;
|
||||
this.Context.CurrentConnectionConfig.ConnectionString = this.MasterConnection.ConnectionString;
|
||||
|
@@ -25,6 +25,10 @@ namespace SqlSugar
|
||||
/// </summary>
|
||||
public InitKeyType InitKeyType = InitKeyType.SystemTable;
|
||||
/// <summary>
|
||||
///If true, there is only one connection instance in the same thread within the same connection string
|
||||
/// </summary>
|
||||
public bool IsShardSameThread { get; set; }
|
||||
/// <summary>
|
||||
/// Configure External Services replace default services,For example, Redis storage
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
|
@@ -10,7 +10,38 @@ namespace SqlSugar
|
||||
public partial class SqlSugarAccessory
|
||||
{
|
||||
#region Properties
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public SqlSugarClient Context
|
||||
{
|
||||
get
|
||||
{
|
||||
var result = _Context; ;
|
||||
if (CurrentConnectionConfig.IsShardSameThread)
|
||||
{
|
||||
if (CallContext.ContextList.Value.IsNullOrEmpty())
|
||||
{
|
||||
CallContext.ContextList.Value = new List<SqlSugarClient>();
|
||||
CallContext.ContextList.Value.Add(_Context);
|
||||
}
|
||||
else
|
||||
{
|
||||
var cacheContext = CallContext.ContextList.Value.FirstOrDefault(it =>
|
||||
it.CurrentConnectionConfig.ConnectionString == _Context.CurrentConnectionConfig.ConnectionString &&
|
||||
it.CurrentConnectionConfig.DbType == _Context.CurrentConnectionConfig.DbType &&
|
||||
it.CurrentConnectionConfig.IsAutoCloseConnection == _Context.CurrentConnectionConfig.IsAutoCloseConnection &&
|
||||
it.CurrentConnectionConfig.IsShardSameThread == _Context.CurrentConnectionConfig.IsShardSameThread);
|
||||
if (cacheContext != null)
|
||||
{
|
||||
return cacheContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
set
|
||||
{
|
||||
_Context = value;
|
||||
}
|
||||
}
|
||||
public ConnectionConfig CurrentConnectionConfig { get; set; }
|
||||
public Dictionary<string, object> TempItems { get; set; }
|
||||
public bool IsSystemTablesConfig { get { return this.CurrentConnectionConfig.InitKeyType == InitKeyType.SystemTable; } }
|
||||
@@ -22,6 +53,7 @@ namespace SqlSugar
|
||||
|
||||
#region Fields
|
||||
protected ISqlBuilder _SqlBuilder;
|
||||
public SqlSugarClient _Context { get; set; }
|
||||
protected EntityMaintenance _EntityProvider;
|
||||
protected IAdo _Ado;
|
||||
protected ILambdaExpressions _LambdaExpressions;
|
||||
@@ -287,7 +319,7 @@ namespace SqlSugar
|
||||
else
|
||||
{
|
||||
isJoinType = false;
|
||||
joinValue += joinValue==null?item:(","+item);
|
||||
joinValue += joinValue == null ? item : ("," + item);
|
||||
}
|
||||
if (isLast)
|
||||
{
|
||||
|
@@ -28,7 +28,7 @@ namespace SqlSugar
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Check.Exception(true, "MySql.Data.dll Nuget更新到 6.10.3-rc 版本的(Core 2.0只支持当前版本), 再检查连接字符串是否正确,{0}", ex.Message);
|
||||
Check.Exception(true, "MySql.Data.dll Nuget更新到 6.10.4 版本的(Core 2.0只支持当前版本), 再检查连接字符串是否正确,{0}", ex.Message);
|
||||
}
|
||||
}
|
||||
return base._DbConnection;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Version>4.5.9.5</Version>
|
||||
<Version>4.5.9.6</Version>
|
||||
<Copyright>sun_kai_xuan</Copyright>
|
||||
<PackageProjectUrl>https://github.com/sunkaixuan/SqlSugar</PackageProjectUrl>
|
||||
<PackageLicenseUrl></PackageLicenseUrl>
|
||||
@@ -13,7 +13,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.0.0" />
|
||||
<PackageReference Include="Mono.Data.OracleClientCore" Version="1.0.0" />
|
||||
<PackageReference Include="MySql.Data" Version="6.10.3-rc" />
|
||||
<PackageReference Include="MySql.Data" Version="6.10.4" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
<PackageReference Include="System.Data.Common" Version="4.3.0" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
|
||||
|
@@ -22,6 +22,7 @@ namespace SqlSugar
|
||||
{
|
||||
base.Context = this;
|
||||
base.CurrentConnectionConfig = config;
|
||||
base.ContextID = Guid.NewGuid();
|
||||
Check.ArgumentNullException(config, "config is null");
|
||||
switch (config.DbType)
|
||||
{
|
||||
@@ -50,41 +51,41 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Ado == null)
|
||||
if (base.Context._Ado == null)
|
||||
{
|
||||
var reval = InstanceFactory.GetAdo(base.CurrentConnectionConfig);
|
||||
_Ado = reval;
|
||||
reval.Context = this;
|
||||
var reval = InstanceFactory.GetAdo(base.Context.CurrentConnectionConfig);
|
||||
base.Context._Ado = reval;
|
||||
reval.Context = base.Context;
|
||||
return reval;
|
||||
}
|
||||
return _Ado;
|
||||
return base.Context._Ado;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Aop Log Methods
|
||||
public virtual AopProvider Aop { get { return new AopProvider(this.Context); } }
|
||||
public virtual AopProvider Aop { get { return new AopProvider(base.Context); } }
|
||||
#endregion
|
||||
|
||||
#region Util Methods
|
||||
[Obsolete("Use SqlSugarClient.Utilities")]
|
||||
public virtual IContextMethods RewritableMethods
|
||||
{
|
||||
get { return this.Utilities; }
|
||||
set { this.Utilities = value; }
|
||||
get { return base.Context.Utilities; }
|
||||
set { base.Context.Utilities = value; }
|
||||
}
|
||||
public virtual IContextMethods Utilities
|
||||
{
|
||||
get
|
||||
{
|
||||
if (base._RewritableMethods == null)
|
||||
if (base.Context._RewritableMethods == null)
|
||||
{
|
||||
base._RewritableMethods = new ContextMethods();
|
||||
base._RewritableMethods.Context = this;
|
||||
base.Context._RewritableMethods = new ContextMethods();
|
||||
base.Context._RewritableMethods.Context = base.Context;
|
||||
}
|
||||
return _RewritableMethods;
|
||||
return base.Context._RewritableMethods;
|
||||
}
|
||||
set { base._RewritableMethods = value; }
|
||||
set { base.Context._RewritableMethods = value; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -313,7 +314,7 @@ namespace SqlSugar
|
||||
|
||||
public virtual ISugarQueryable<T> UnionAll<T>(params ISugarQueryable<T>[] queryables) where T : class, new()
|
||||
{
|
||||
var sqlBuilder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig);
|
||||
var sqlBuilder = InstanceFactory.GetSqlbuilder(base.Context.CurrentConnectionConfig);
|
||||
Check.Exception(queryables.IsNullOrEmpty(), "UnionAll.queryables is null ");
|
||||
int i = 1;
|
||||
List<KeyValuePair<string, List<SugarParameter>>> allItems = new List<KeyValuePair<string, List<SugarParameter>>>();
|
||||
@@ -330,7 +331,7 @@ namespace SqlSugar
|
||||
}
|
||||
var allSql = sqlBuilder.GetUnionAllSql(allItems.Select(it => it.Key).ToList());
|
||||
var allParameters = allItems.SelectMany(it => it.Value).ToArray();
|
||||
var resulut = this.Queryable<ExpandoObject>().AS(UtilMethods.GetPackTable(allSql, "unionTable"));
|
||||
var resulut = base.Context.Queryable<ExpandoObject>().AS(UtilMethods.GetPackTable(allSql, "unionTable"));
|
||||
resulut.AddParameters(allParameters);
|
||||
return resulut.Select<T>("*");
|
||||
}
|
||||
@@ -344,8 +345,8 @@ namespace SqlSugar
|
||||
#region SqlQueryable
|
||||
public ISugarQueryable<T> SqlQueryable<T>(string sql) where T : class, new()
|
||||
{
|
||||
var sqlBuilder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig);
|
||||
return this.Queryable<T>().AS(sqlBuilder.GetPackTable(sql, sqlBuilder.GetDefaultShortName())).Select("*");
|
||||
var sqlBuilder = InstanceFactory.GetSqlbuilder(base.Context.CurrentConnectionConfig);
|
||||
return base.Context.Queryable<T>().AS(sqlBuilder.GetPackTable(sql, sqlBuilder.GetDefaultShortName())).Select("*");
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -359,33 +360,33 @@ namespace SqlSugar
|
||||
public virtual IInsertable<T> Insertable<T>(List<T> insertObjs) where T : class, new()
|
||||
{
|
||||
Check.ArgumentNullException(insertObjs, "Insertable.insertObjs can't be null");
|
||||
return this.Insertable(insertObjs.ToArray());
|
||||
return base.Context.Insertable(insertObjs.ToArray());
|
||||
}
|
||||
public virtual IInsertable<T> Insertable<T>(T insertObj) where T : class, new()
|
||||
{
|
||||
return this.Insertable(new T[] { insertObj });
|
||||
return base.Context.Insertable(new T[] { insertObj });
|
||||
}
|
||||
public virtual IInsertable<T> Insertable<T>(Dictionary<string, object> columnDictionary) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
Check.Exception(columnDictionary == null || columnDictionary.Count == 0, "Insertable.columnDictionary can't be null");
|
||||
var insertObject = this.Utilities.DeserializeObject<T>(this.Utilities.SerializeObject(columnDictionary));
|
||||
var insertObject = base.Context.Utilities.DeserializeObject<T>(base.Context.Utilities.SerializeObject(columnDictionary));
|
||||
var columns = columnDictionary.Select(it => it.Key).ToList();
|
||||
return this.Insertable(insertObject).InsertColumns(it => columns.Any(c => it.Equals(c, StringComparison.CurrentCultureIgnoreCase))); ;
|
||||
return base.Context.Insertable(insertObject).InsertColumns(it => columns.Any(c => it.Equals(c, StringComparison.CurrentCultureIgnoreCase))); ;
|
||||
}
|
||||
public virtual IInsertable<T> Insertable<T>(dynamic insertDynamicObject) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
if (insertDynamicObject is T)
|
||||
{
|
||||
return this.Insertable((T)insertDynamicObject);
|
||||
return base.Context.Insertable((T)insertDynamicObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
var columns = ((object)insertDynamicObject).GetType().GetProperties().Select(it => it.Name).ToList();
|
||||
Check.Exception(columns.IsNullOrEmpty(), "Insertable.updateDynamicObject can't be null");
|
||||
T insertObject = this.Utilities.DeserializeObject<T>(this.Utilities.SerializeObject(insertDynamicObject));
|
||||
return this.Insertable(insertObject).InsertColumns(it => columns.Any(c => it.Equals(c, StringComparison.CurrentCultureIgnoreCase)));
|
||||
T insertObject = base.Context.Utilities.DeserializeObject<T>(base.Context.Utilities.SerializeObject(insertDynamicObject));
|
||||
return base.Context.Insertable(insertObject).InsertColumns(it => columns.Any(c => it.Equals(c, StringComparison.CurrentCultureIgnoreCase)));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@@ -400,32 +401,32 @@ namespace SqlSugar
|
||||
public virtual IDeleteable<T> Deleteable<T>(Expression<Func<T, bool>> expression) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Deleteable<T>().Where(expression);
|
||||
return base.Context.Deleteable<T>().Where(expression);
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(dynamic primaryKeyValue) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Deleteable<T>().In(primaryKeyValue);
|
||||
return base.Context.Deleteable<T>().In(primaryKeyValue);
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(dynamic[] primaryKeyValues) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Deleteable<T>().In(primaryKeyValues);
|
||||
return base.Context.Deleteable<T>().In(primaryKeyValues);
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(List<dynamic> pkValue) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Deleteable<T>().In(pkValue);
|
||||
return base.Context.Deleteable<T>().In(pkValue);
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(T deleteObj) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Deleteable<T>().Where(deleteObj);
|
||||
return base.Context.Deleteable<T>().Where(deleteObj);
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(List<T> deleteObjs) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Deleteable<T>().Where(deleteObjs);
|
||||
return base.Context.Deleteable<T>().Where(deleteObjs);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -443,33 +444,33 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual IUpdateable<T> Updateable<T>(T UpdateObj) where T : class, new()
|
||||
{
|
||||
return this.Updateable(new T[] { UpdateObj });
|
||||
return base.Context.Updateable(new T[] { UpdateObj });
|
||||
}
|
||||
public virtual IUpdateable<T> Updateable<T>() where T : class, new()
|
||||
{
|
||||
return this.Updateable(new T[] { new T() });
|
||||
return base.Context.Updateable(new T[] { new T() });
|
||||
}
|
||||
public virtual IUpdateable<T> Updateable<T>(Dictionary<string, object> columnDictionary) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
Check.Exception(columnDictionary == null || columnDictionary.Count == 0, "Updateable.columnDictionary can't be null");
|
||||
var updateObject = this.Utilities.DeserializeObject<T>(this.Utilities.SerializeObject(columnDictionary));
|
||||
var updateObject = base.Context.Utilities.DeserializeObject<T>(base.Context.Utilities.SerializeObject(columnDictionary));
|
||||
var columns = columnDictionary.Select(it => it.Key).ToList();
|
||||
return this.Updateable(updateObject).UpdateColumns(it => columns.Any(c => it.Equals(c, StringComparison.CurrentCultureIgnoreCase))); ;
|
||||
return base.Context.Updateable(updateObject).UpdateColumns(it => columns.Any(c => it.Equals(c, StringComparison.CurrentCultureIgnoreCase))); ;
|
||||
}
|
||||
public virtual IUpdateable<T> Updateable<T>(dynamic updateDynamicObject) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
if (updateDynamicObject is T)
|
||||
{
|
||||
return this.Updateable((T)updateDynamicObject);
|
||||
return base.Context.Updateable((T)updateDynamicObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
var columns = ((object)updateDynamicObject).GetType().GetProperties().Select(it => it.Name).ToList();
|
||||
Check.Exception(columns.IsNullOrEmpty(), "Updateable.updateDynamicObject can't be null");
|
||||
T updateObject = this.Utilities.DeserializeObject<T>(this.Utilities.SerializeObject(updateDynamicObject));
|
||||
return this.Updateable(updateObject).UpdateColumns(it => columns.Any(c => it.Equals(c, StringComparison.CurrentCultureIgnoreCase))); ;
|
||||
T updateObject = base.Context.Utilities.DeserializeObject<T>(base.Context.Utilities.SerializeObject(updateDynamicObject));
|
||||
return base.Context.Updateable(updateObject).UpdateColumns(it => columns.Any(c => it.Equals(c, StringComparison.CurrentCultureIgnoreCase))); ;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@@ -479,8 +480,8 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
IDbFirst dbFirst = InstanceFactory.GetDbFirst(this.Context.CurrentConnectionConfig);
|
||||
dbFirst.Context = this.Context;
|
||||
IDbFirst dbFirst = InstanceFactory.GetDbFirst(base.Context.CurrentConnectionConfig);
|
||||
dbFirst.Context = base.Context;
|
||||
dbFirst.Init();
|
||||
return dbFirst;
|
||||
}
|
||||
@@ -492,8 +493,8 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
ICodeFirst codeFirst = InstanceFactory.GetCodeFirst(this.Context.CurrentConnectionConfig);
|
||||
codeFirst.Context = this.Context;
|
||||
ICodeFirst codeFirst = InstanceFactory.GetCodeFirst(base.Context.CurrentConnectionConfig);
|
||||
codeFirst.Context = base.Context;
|
||||
return codeFirst;
|
||||
}
|
||||
}
|
||||
@@ -504,13 +505,13 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
if (base._DbMaintenance == null)
|
||||
if (base.Context._DbMaintenance == null)
|
||||
{
|
||||
IDbMaintenance maintenance = InstanceFactory.GetDbMaintenance(this.Context.CurrentConnectionConfig);
|
||||
base._DbMaintenance = maintenance;
|
||||
maintenance.Context = this.Context;
|
||||
IDbMaintenance maintenance = InstanceFactory.GetDbMaintenance(base.Context.CurrentConnectionConfig);
|
||||
base.Context._DbMaintenance = maintenance;
|
||||
maintenance.Context = base.Context;
|
||||
}
|
||||
return base._DbMaintenance;
|
||||
return base.Context._DbMaintenance;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@@ -519,21 +520,21 @@ namespace SqlSugar
|
||||
[Obsolete("Use SqlSugarClient.EntityMaintenance")]
|
||||
public virtual EntityMaintenance EntityProvider
|
||||
{
|
||||
get { return this.EntityMaintenance; }
|
||||
set { this.EntityMaintenance = value; }
|
||||
get { return base.Context.EntityMaintenance; }
|
||||
set { base.Context.EntityMaintenance = value; }
|
||||
}
|
||||
public virtual EntityMaintenance EntityMaintenance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (base._EntityProvider == null)
|
||||
if (base.Context._EntityProvider == null)
|
||||
{
|
||||
base._EntityProvider = new EntityMaintenance();
|
||||
base._EntityProvider.Context = this;
|
||||
base.Context._EntityProvider = new EntityMaintenance();
|
||||
base.Context._EntityProvider.Context = base.Context;
|
||||
}
|
||||
return _EntityProvider;
|
||||
return base.Context._EntityProvider;
|
||||
}
|
||||
set { base._EntityProvider = value; }
|
||||
set { base.Context._EntityProvider = value; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -542,14 +543,14 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
if (base._QueryFilterProvider == null)
|
||||
if (base.Context._QueryFilterProvider == null)
|
||||
{
|
||||
base._QueryFilterProvider = new QueryFilterProvider();
|
||||
base._QueryFilterProvider.Context = this;
|
||||
base.Context._QueryFilterProvider = new QueryFilterProvider();
|
||||
base.Context._QueryFilterProvider.Context = base.Context;
|
||||
}
|
||||
return _QueryFilterProvider;
|
||||
return base.Context._QueryFilterProvider;
|
||||
}
|
||||
set { base._QueryFilterProvider = value; }
|
||||
set { base.Context._QueryFilterProvider = value; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -558,9 +559,9 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_SimpleClient == null)
|
||||
_SimpleClient = new SimpleClient(this);
|
||||
return _SimpleClient;
|
||||
if (base.Context._SimpleClient == null)
|
||||
base.Context._SimpleClient = new SimpleClient(base.Context);
|
||||
return base.Context._SimpleClient;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@@ -568,13 +569,13 @@ namespace SqlSugar
|
||||
#region Dispose OR Close
|
||||
public virtual void Close()
|
||||
{
|
||||
if (this.Ado != null)
|
||||
this.Ado.Close();
|
||||
if (base.Context.Ado != null)
|
||||
base.Context.Ado.Close();
|
||||
}
|
||||
public virtual void Dispose()
|
||||
{
|
||||
if (this.Ado != null)
|
||||
this.Ado.Dispose();
|
||||
if (base.Context.Ado != null)
|
||||
base.Context.Ado.Dispose();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
<package >
|
||||
<metadata>
|
||||
<id>sqlSugarCore</id>
|
||||
<version>4.5.9.5</version>
|
||||
<version>4.5.9.6</version>
|
||||
<authors>sunkaixuan</authors>
|
||||
<owners>Landa</owners>
|
||||
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>
|
||||
@@ -19,6 +19,7 @@
|
||||
<dependency id="Newtonsoft.Json" version="10.0.3" />
|
||||
<dependency id="Microsoft.Data.Sqlite" version="2.0.0" />
|
||||
<dependency id="System.Reflection.Emit.Lightweight" version="4.3.0" />
|
||||
<dependency id="MySql.Data" version="6.10.4" />
|
||||
</group>
|
||||
</dependencies>
|
||||
</metadata>
|
||||
|
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
internal class CallContext
|
||||
{
|
||||
public static ThreadLocal<List<SqlSugarClient>> ContextList = new ThreadLocal<List<SqlSugarClient>>();
|
||||
}
|
||||
}
|
Binary file not shown.
Reference in New Issue
Block a user