diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs index bbdeba555..ea3c6f3d3 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs @@ -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) { diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs index d89986f36..96cf92b1d 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs @@ -170,7 +170,15 @@ namespace SqlSugar /// the code annotation for the database table 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; + } } /// /// Gets the code annotation for the field @@ -180,7 +188,15 @@ namespace SqlSugar /// the code annotation for the field 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 - } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs index b5fb44f37..2547d4300 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs @@ -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; } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/InsertBuilder.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/InsertBuilder.cs index a5fb8332a..17e4027f8 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/InsertBuilder.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/InsertBuilder.cs @@ -30,6 +30,7 @@ namespace SqlSugar public EntityInfo EntityInfo { get; set; } public Dictionary OracleSeqInfoList { get; set; } public bool IsBlukCopy { get; set; } + public virtual bool IsOleDb { get; set; } #endregion #region SqlTemplate diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs index 73466e287..e78dd9351 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs @@ -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"); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConnMoreSettings.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConnMoreSettings.cs index bdab95bf4..2ab3dafb7 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConnMoreSettings.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConnMoreSettings.cs @@ -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; } } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/ContextMethods.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/ContextMethods.cs index 17bbbe621..e84935a46 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/ContextMethods.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/ContextMethods.cs @@ -726,12 +726,22 @@ namespace SqlSugar } else { - IConditionalModel conditionalModel = new ConditionalModel() + var typeValue = item["ConditionalType"].Value(); + + ConditionalModel conditionalModel = new ConditionalModel() { - ConditionalType = (ConditionalType)Convert.ToInt32(item["ConditionalType"].Value()), + // ConditionalType = (ConditionalType)Convert.ToInt32(), FieldName = item["FieldName"] + "", FieldValue = item["FieldValue"].Value()==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); } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/InstanceFactory.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/InstanceFactory.cs index 30974c68e..c733365c3 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/InstanceFactory.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/InstanceFactory.cs @@ -11,7 +11,9 @@ namespace SqlSugar { static Assembly assembly = Assembly.GetExecutingAssembly(); static Dictionary typeCache = new Dictionary(); - 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(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(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; } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs index 06fbf180d..5ee078454 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs @@ -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); } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs index 0f28493f2..15b1f4f16 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs @@ -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);