mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-12-26 14:15:50 +08:00
Update Core
This commit is contained in:
@@ -400,7 +400,14 @@ namespace SqlSugar
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return properyTypeName != dataType;
|
||||
if (properyTypeName == null || dataType == null)
|
||||
{
|
||||
return properyTypeName != dataType;
|
||||
}
|
||||
else
|
||||
{
|
||||
return properyTypeName.ToLower() != dataType.ToLower();
|
||||
}
|
||||
}
|
||||
private static string GetType(string name)
|
||||
{
|
||||
|
||||
@@ -170,7 +170,15 @@ namespace SqlSugar
|
||||
/// <returns>the code annotation for the database table</returns>
|
||||
public string GetTableAnnotation(Type entityType)
|
||||
{
|
||||
return GetXElementNodeValue(entityType, $"T:{entityType.FullName}");
|
||||
var result= GetXElementNodeValue(entityType, $"T:{entityType.FullName}");
|
||||
if (string.IsNullOrEmpty(result))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the code annotation for the field
|
||||
@@ -180,7 +188,15 @@ namespace SqlSugar
|
||||
/// <returns>the code annotation for the field</returns>
|
||||
public string GetPropertyAnnotation(Type entityType, string dbColumnName)
|
||||
{
|
||||
return GetXElementNodeValue(entityType, $"P:{entityType.FullName}.{dbColumnName}");
|
||||
var result= GetXElementNodeValue(entityType, $"P:{entityType.FullName}.{dbColumnName}");
|
||||
if (string.IsNullOrEmpty(result))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
#region Primary key
|
||||
@@ -269,6 +285,5 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,27 @@ namespace SqlSugar
|
||||
return 0;
|
||||
}
|
||||
string sql = _ExecuteReturnIdentity();
|
||||
var result = Ado.GetInt(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
var result = 0;
|
||||
if (InsertBuilder.IsOleDb)
|
||||
{
|
||||
var isAuto = false;
|
||||
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection)
|
||||
{
|
||||
isAuto = true;
|
||||
this.Context.CurrentConnectionConfig.IsAutoCloseConnection = false;
|
||||
}
|
||||
result = Ado.GetInt(sql.Split(';').First(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
result = Ado.GetInt(sql.Split(';').Last(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
if (isAuto)
|
||||
{
|
||||
this.Ado.Close();
|
||||
this.Context.CurrentConnectionConfig.IsAutoCloseConnection = isAuto;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = Ado.GetInt(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
}
|
||||
After(sql, result);
|
||||
return result;
|
||||
}
|
||||
@@ -81,7 +101,27 @@ namespace SqlSugar
|
||||
return 0;
|
||||
}
|
||||
string sql = _ExecuteReturnBigIdentity();
|
||||
var result = Convert.ToInt64(Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()));
|
||||
long result = 0;
|
||||
if (InsertBuilder.IsOleDb)
|
||||
{
|
||||
var isAuto = false;
|
||||
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection)
|
||||
{
|
||||
isAuto = true;
|
||||
this.Context.CurrentConnectionConfig.IsAutoCloseConnection = false;
|
||||
}
|
||||
result = Convert.ToInt64(Ado.GetScalar(sql.Split(';').First(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()));
|
||||
result = Convert.ToInt64(Ado.GetScalar(sql.Split(';').Last(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()));
|
||||
if (isAuto)
|
||||
{
|
||||
this.Ado.Close();
|
||||
this.Context.CurrentConnectionConfig.IsAutoCloseConnection = isAuto;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result= Convert.ToInt64(Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()));
|
||||
}
|
||||
After(sql, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace SqlSugar
|
||||
public EntityInfo EntityInfo { get; set; }
|
||||
public Dictionary<string, int> OracleSeqInfoList { get; set; }
|
||||
public bool IsBlukCopy { get; set; }
|
||||
public virtual bool IsOleDb { get; set; }
|
||||
#endregion
|
||||
|
||||
#region SqlTemplate
|
||||
|
||||
@@ -382,14 +382,15 @@ namespace SqlSugar
|
||||
DependencyManagement.TryOscar();
|
||||
break;
|
||||
case DbType.MySqlConnector:
|
||||
InstanceFactory.CustomTypeName = SugarCompatible.IsFramework?"SqlSugar.MySqlConnector": "SqlSugar.MySqlConnectorCore";
|
||||
InstanceFactory.CustomDllName = SugarCompatible.IsFramework?"SqlSugar.MySqlConnector": "SqlSugar.MySqlConnectorCore";
|
||||
break;
|
||||
case DbType.Access:
|
||||
InstanceFactory.CustomTypeName = SugarCompatible.IsFramework?"SqlSugar.Access": "SqlSugar.AccessCore";
|
||||
InstanceFactory.CustomDllName = SugarCompatible.IsFramework?"SqlSugar.Access": "SqlSugar.AccessCore";
|
||||
break;
|
||||
case DbType.Custom:
|
||||
Check.Exception(config?.MoreSettings?.CustomNugetDllName == null,ErrorMessage.GetThrowMessage("if DbType is Custmon , ConnectionConfig.MoreSettings.CustomNugetDbName is not null", "DbType是Custom ,而需要设置外部数据库支持dll名称。示例: ConnectionConfig.MoreSettings.CustomNugetDllName=\"SqlSugar.DB2\" , 设置完后我们需要引用SqlSugar.DB2.dll "));
|
||||
InstanceFactory.CustomTypeName = config.MoreSettings.CustomNugetDllName;
|
||||
Check.Exception(InstanceFactory.CustomDbName==null , "DbType.Custom: InstanceFactory.CustomDbName is not null ");
|
||||
Check.Exception(InstanceFactory.CustomNamespace == null, "DbType.Custom: InstanceFactory.CustomNamespace is not null ");
|
||||
Check.Exception(InstanceFactory.CustomDllName == null, "DbType.Custom: InstanceFactory.CustomDllName is not null ");
|
||||
break;
|
||||
default:
|
||||
throw new Exception("ConnectionConfig.DbType is null");
|
||||
|
||||
@@ -13,7 +13,6 @@ namespace SqlSugar
|
||||
public bool DisableNvarchar { get; set; }
|
||||
public bool PgSqlIsAutoToLower = true;
|
||||
public int DefaultCacheDurationInSeconds { get; set; }
|
||||
public bool? TableEnumIsString { get; set; }
|
||||
public string CustomNugetDllName { get; set; }
|
||||
public bool? TableEnumIsString { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -726,12 +726,22 @@ namespace SqlSugar
|
||||
}
|
||||
else
|
||||
{
|
||||
IConditionalModel conditionalModel = new ConditionalModel()
|
||||
var typeValue = item["ConditionalType"].Value<object>();
|
||||
|
||||
ConditionalModel conditionalModel = new ConditionalModel()
|
||||
{
|
||||
ConditionalType = (ConditionalType)Convert.ToInt32(item["ConditionalType"].Value<int>()),
|
||||
// ConditionalType = (ConditionalType)Convert.ToInt32(),
|
||||
FieldName = item["FieldName"] + "",
|
||||
FieldValue = item["FieldValue"].Value<string>()==null?null: item["FieldValue"].ToString()
|
||||
};
|
||||
if (typeValue.IsInt())
|
||||
{
|
||||
conditionalModel.ConditionalType = (ConditionalType)Convert.ToInt32(typeValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
conditionalModel.ConditionalType = (ConditionalType)Enum.Parse(typeof(ConditionalType),typeValue.ObjToString());
|
||||
}
|
||||
conditionalModels.Add(conditionalModel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,9 @@ namespace SqlSugar
|
||||
{
|
||||
static Assembly assembly = Assembly.GetExecutingAssembly();
|
||||
static Dictionary<string, Type> typeCache = new Dictionary<string, Type>();
|
||||
public static string CustomTypeName = "";
|
||||
public static string CustomDllName = "";
|
||||
public static string CustomDbName = "";
|
||||
public static string CustomNamespace = "";
|
||||
public static bool NoCache = false;
|
||||
|
||||
public static void RemoveCache()
|
||||
@@ -309,18 +311,18 @@ namespace SqlSugar
|
||||
}
|
||||
else if (type == "Access")
|
||||
{
|
||||
return "SqlSugar.MySqlConnector.Access" + name;
|
||||
return "SqlSugar.Access.Access" + name;
|
||||
}
|
||||
else if (type == "Custom")
|
||||
{
|
||||
return "SqlSugar.MySqlConnector.MySql" + name;
|
||||
return CustomNamespace + "."+CustomDbName + name;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!string.IsNullOrEmpty(CustomTypeName))
|
||||
{
|
||||
type = CustomTypeName;
|
||||
}
|
||||
//if (!string.IsNullOrEmpty(CustomDllName))
|
||||
//{
|
||||
// type = CustomDllName;
|
||||
//}
|
||||
return UtilConstants.AssemblyName + "." + type + name;
|
||||
}
|
||||
}
|
||||
@@ -410,13 +412,17 @@ namespace SqlSugar
|
||||
{
|
||||
lock (typeCache)
|
||||
{
|
||||
if (string.IsNullOrEmpty(CustomTypeName))
|
||||
if (string.IsNullOrEmpty(CustomDllName))
|
||||
{
|
||||
type = Type.GetType(className + "`" + types.Length, true).MakeGenericType(types);
|
||||
}
|
||||
else
|
||||
{
|
||||
type = GetCustomTypeByClass(className + "`" + types.Length).MakeGenericType(types);
|
||||
if (type == null)
|
||||
{
|
||||
type = Type.GetType(className + "`" + types.Length, true).MakeGenericType(types);
|
||||
}
|
||||
}
|
||||
Check.ArgumentNullException(type, string.Format(ErrorMessage.ObjNotExist, className));
|
||||
if (!typeCache.ContainsKey(cacheKey))
|
||||
@@ -432,13 +438,17 @@ namespace SqlSugar
|
||||
{
|
||||
|
||||
Type type = null;
|
||||
if (string.IsNullOrEmpty(CustomTypeName))
|
||||
if (string.IsNullOrEmpty(CustomDllName))
|
||||
{
|
||||
type = Type.GetType(className + "`" + types.Length, true).MakeGenericType(types);
|
||||
}
|
||||
else
|
||||
{
|
||||
type = GetCustomTypeByClass(className + "`" + types.Length).MakeGenericType(types);
|
||||
if (type == null)
|
||||
{
|
||||
type = Type.GetType(className + "`" + types.Length, true).MakeGenericType(types);
|
||||
}
|
||||
}
|
||||
var result = (Restult)Activator.CreateInstance(type, true);
|
||||
return result;
|
||||
@@ -488,7 +498,7 @@ namespace SqlSugar
|
||||
private static T NoCacheGetCacheInstance<T>(string className)
|
||||
{
|
||||
Type type = null;
|
||||
if (string.IsNullOrEmpty(CustomTypeName))
|
||||
if (string.IsNullOrEmpty(CustomDllName))
|
||||
{
|
||||
type=assembly.GetType(className);
|
||||
}
|
||||
@@ -502,15 +512,15 @@ namespace SqlSugar
|
||||
|
||||
internal static Type GetCustomTypeByClass(string className)
|
||||
{
|
||||
var key = "Assembly_"+ CustomTypeName+assembly.GetHashCode();
|
||||
var key = "Assembly_"+ CustomDllName+assembly.GetHashCode();
|
||||
var newAssembly = new ReflectionInoCacheService().GetOrCreate<Assembly>(key, () => {
|
||||
try
|
||||
{
|
||||
return Assembly.LoadFrom(CustomTypeName + ".dll");
|
||||
return Assembly.LoadFrom(CustomDllName + ".dll");
|
||||
}
|
||||
catch
|
||||
{
|
||||
var message = "Not Found " + CustomTypeName + ".dll";
|
||||
var message = "Not Found " + CustomDllName + ".dll";
|
||||
Check.Exception(true, message);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -342,6 +342,10 @@ namespace SqlSugar
|
||||
if (item.ColumnDescription != null)
|
||||
{
|
||||
var mySqlCodeFirst = this.Context.CodeFirst as MySqlCodeFirst;
|
||||
if (item.UnderType == UtilConstants.GuidType&&item.Length==0)
|
||||
{
|
||||
item.Length = 36;
|
||||
}
|
||||
string sql = GetUpdateColumnSql(entity.DbTableName, mySqlCodeFirst.GetEntityColumnToDbColumn(entity, entity.DbTableName, item))+" "+(item.IsIdentity? "AUTO_INCREMENT" : "")+" " + " COMMENT '" + item.ColumnDescription + "'";
|
||||
db.Ado.ExecuteCommand(sql);
|
||||
}
|
||||
|
||||
@@ -242,6 +242,18 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
public override bool AddColumnRemark(string columnName, string tableName, string description)
|
||||
{
|
||||
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
||||
string sql = string.Format(this.AddColumnRemarkSql, columnName, tableName, description);
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
public override bool AddTableRemark(string tableName, string description)
|
||||
{
|
||||
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
||||
return base.AddTableRemark(tableName, description);
|
||||
}
|
||||
public override bool UpdateColumn(string tableName, DbColumnInfo columnInfo)
|
||||
{
|
||||
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
||||
|
||||
Reference in New Issue
Block a user