mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 13:34:32 +08:00
Synchronization code
This commit is contained in:
parent
f9c61ec052
commit
30cf83149d
@ -6,13 +6,13 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace SqlSugar
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
internal class ReSetValueBySqlExpListModel
|
public class ReSetValueBySqlExpListModel
|
||||||
{
|
{
|
||||||
public string DbColumnName { get; set; }
|
public string DbColumnName { get; set; }
|
||||||
public string Sql { get; set; }
|
public string Sql { get; set; }
|
||||||
public ReSetValueBySqlExpListModelType? Type { get; set; }
|
public ReSetValueBySqlExpListModelType? Type { get; set; }
|
||||||
}
|
}
|
||||||
internal enum ReSetValueBySqlExpListModelType
|
public enum ReSetValueBySqlExpListModelType
|
||||||
{
|
{
|
||||||
Default,
|
Default,
|
||||||
List
|
List
|
||||||
|
@ -36,7 +36,7 @@ namespace SqlSugar
|
|||||||
public List<string> UpdateColumns { get; set; }
|
public List<string> UpdateColumns { get; set; }
|
||||||
public List<JoinQueryInfo> JoinInfos { get; set; }
|
public List<JoinQueryInfo> JoinInfos { get; set; }
|
||||||
public string ShortName { get; set; }
|
public string ShortName { get; set; }
|
||||||
internal Dictionary<string, ReSetValueBySqlExpListModel> ReSetValueBySqlExpList { get; set; }
|
public Dictionary<string, ReSetValueBySqlExpListModel> ReSetValueBySqlExpList { get; set; }
|
||||||
public virtual string ReSetValueBySqlExpListType { get; set; }
|
public virtual string ReSetValueBySqlExpListType { get; set; }
|
||||||
public virtual string SqlTemplate
|
public virtual string SqlTemplate
|
||||||
{
|
{
|
||||||
|
@ -412,7 +412,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
return N;
|
return N;
|
||||||
}
|
}
|
||||||
internal bool IsVarchar()
|
public bool IsVarchar()
|
||||||
{
|
{
|
||||||
if (_Context.CurrentConnectionConfig.MoreSettings != null && _Context.CurrentConnectionConfig.MoreSettings.DisableNvarchar)
|
if (_Context.CurrentConnectionConfig.MoreSettings != null && _Context.CurrentConnectionConfig.MoreSettings.DisableNvarchar)
|
||||||
{
|
{
|
||||||
@ -442,7 +442,7 @@ namespace SqlSugar
|
|||||||
Check.ExceptionEasy("Use DbType.PostgreSQL , ConnectionString add No Reset On Close=true", "OpenGausso数据库请使用DbType.PostgreSQL 并且连接字符串加上 No Reset On Close=true");
|
Check.ExceptionEasy("Use DbType.PostgreSQL , ConnectionString add No Reset On Close=true", "OpenGausso数据库请使用DbType.PostgreSQL 并且连接字符串加上 No Reset On Close=true");
|
||||||
break;
|
break;
|
||||||
case DbType.HG:
|
case DbType.HG:
|
||||||
Check.ExceptionEasy("Use DbType.PostgreSQL", "瀚高数据库请使用DbType.PostgreSQL");
|
InstanceFactory.CustomDllName = SugarCompatible.IsFramework ? throw new Exception("Only.NET CORE is supported") : "SqlSugar.HGCore";
|
||||||
break;
|
break;
|
||||||
case DbType.Kdbndp:
|
case DbType.Kdbndp:
|
||||||
DependencyManagement.TryKdbndb();
|
DependencyManagement.TryKdbndb();
|
||||||
|
@ -30,6 +30,6 @@ namespace SqlSugar
|
|||||||
public string InsertSql { get; set; }
|
public string InsertSql { get; set; }
|
||||||
public bool UpdateServerTime { get; set; }
|
public bool UpdateServerTime { get; set; }
|
||||||
public string UpdateSql { get; set; }
|
public string UpdateSql { get; set; }
|
||||||
internal object SqlParameterDbType { get; set; }
|
public object SqlParameterDbType { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -249,12 +249,40 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return new KdbndpInserttable<T>();
|
return new KdbndpInserttable<T>();
|
||||||
}
|
}
|
||||||
|
else if (IsCustomDb(currentConnectionConfig))
|
||||||
|
{
|
||||||
|
var name =
|
||||||
|
"SqlSugar." + currentConnectionConfig.DbType +
|
||||||
|
"." + currentConnectionConfig.DbType
|
||||||
|
+ "Insertable`1";
|
||||||
|
var type = GetCustomTypeByClass<T>(name);
|
||||||
|
if (type == null)
|
||||||
|
{
|
||||||
|
return new InsertableProvider<T>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (InsertableProvider<T>)Activator.CreateInstance(type, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return new InsertableProvider<T>();
|
return new InsertableProvider<T>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool IsCustomDb(ConnectionConfig currentConnectionConfig)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
currentConnectionConfig.DbType != DbType.SqlServer &&
|
||||||
|
currentConnectionConfig.DbType != DbType.Dm &&
|
||||||
|
currentConnectionConfig.DbType != DbType.Oscar &&
|
||||||
|
currentConnectionConfig.DbType != DbType.Access &&
|
||||||
|
currentConnectionConfig.DbType != DbType.QuestDB &&
|
||||||
|
currentConnectionConfig.DbType != DbType.MySql &&
|
||||||
|
GetCustomTypeByClass("SqlSugar." + currentConnectionConfig.DbType + "." + currentConnectionConfig.DbType + "Provider") != null;
|
||||||
|
}
|
||||||
|
|
||||||
public static IDbBind GetDbBind(ConnectionConfig currentConnectionConfig)
|
public static IDbBind GetDbBind(ConnectionConfig currentConnectionConfig)
|
||||||
{
|
{
|
||||||
if (currentConnectionConfig.DbType == DbType.SqlServer)
|
if (currentConnectionConfig.DbType == DbType.SqlServer)
|
||||||
@ -467,7 +495,11 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
if (type == null)
|
if (type == null)
|
||||||
{
|
{
|
||||||
type = Type.GetType(className + "`" + types.Length, true).MakeGenericType(types);
|
type = Type.GetType(className + "`" + types.Length)?.MakeGenericType(types);
|
||||||
|
if (type == null)
|
||||||
|
{
|
||||||
|
type = GetCustomDbType(className + "`" + types.Length, type).MakeGenericType(types);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var result = (Restult)Activator.CreateInstance(type, true);
|
var result = (Restult)Activator.CreateInstance(type, true);
|
||||||
@ -537,10 +569,35 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
type = GetCustomTypeByClass(className);
|
type = GetCustomTypeByClass(className);
|
||||||
}
|
}
|
||||||
|
if (type == null)
|
||||||
|
{
|
||||||
|
type = GetCustomDbType(className, type);
|
||||||
|
}
|
||||||
var result = (T)Activator.CreateInstance(type, true);
|
var result = (T)Activator.CreateInstance(type, true);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Type GetCustomDbType(string className, Type type)
|
||||||
|
{
|
||||||
|
if (className.Replace(".", "").Length + 1 == className.Length)
|
||||||
|
{
|
||||||
|
var array = className.Split('.');
|
||||||
|
foreach (var item in UtilMethods.EnumToDictionary<DbType>())
|
||||||
|
{
|
||||||
|
if (array.Last().StartsWith(item.Value.ToString()))
|
||||||
|
{
|
||||||
|
|
||||||
|
var newName = array.First() + "." + item.Value.ToString() + "." + array.Last();
|
||||||
|
type = GetCustomTypeByClass(newName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
internal static Type GetCustomTypeByClass(string className)
|
internal static Type GetCustomTypeByClass(string className)
|
||||||
{
|
{
|
||||||
var key = "Assembly_"+ CustomDllName+assembly.GetHashCode();
|
var key = "Assembly_"+ CustomDllName+assembly.GetHashCode();
|
||||||
@ -576,6 +633,44 @@ namespace SqlSugar
|
|||||||
Type type = newAssembly.GetType(className);
|
Type type = newAssembly.GetType(className);
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static Type GetCustomTypeByClass<T>(string className)
|
||||||
|
{
|
||||||
|
var key = "Assembly_" + CustomDllName + assembly.GetHashCode();
|
||||||
|
var newAssembly = new ReflectionInoCacheService().GetOrCreate<Assembly>(key, () => {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var path = Assembly.GetExecutingAssembly().Location;
|
||||||
|
if (path.HasValue())
|
||||||
|
{
|
||||||
|
path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(path), CustomDllName + ".dll");
|
||||||
|
}
|
||||||
|
if (path.HasValue() && FileHelper.IsExistFile(path))
|
||||||
|
{
|
||||||
|
return Assembly.LoadFrom(path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (IsWebFrom)
|
||||||
|
{
|
||||||
|
string newpath = (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\" + CustomDllName + ".dll").Replace("file:\\", "");
|
||||||
|
return Assembly.LoadFrom(newpath);
|
||||||
|
}
|
||||||
|
return Assembly.LoadFrom(CustomDllName + ".dll");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
var message = "Not Found " + CustomDllName + ".dll";
|
||||||
|
Check.Exception(true, message);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Type typeArgument = typeof(T);
|
||||||
|
string fullTypeName = className + "[[" + typeArgument.FullName+","+ typeArgument.Assembly.FullName+ "]]";
|
||||||
|
Type type = newAssembly.GetType(fullTypeName);
|
||||||
|
return type;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user