mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-10-15 18:55:07 +08:00
Code optimization
This commit is contained in:
@@ -115,7 +115,7 @@ namespace SqlSugar
|
||||
.Where(ec => !dbColumns.Any(dc => dc.DbColumnName.Equals(ec.OldDbColumnName, StringComparison.CurrentCultureIgnoreCase)))
|
||||
.Where(ec =>
|
||||
dbColumns.Any(dc => dc.DbColumnName.Equals(ec.DbColumnName)
|
||||
&& ((ec.Length != dc.Length && !PubMethod.GetUnderType(ec.PropertyInfo).IsEnum() && PubMethod.GetUnderType(ec.PropertyInfo).IsIn(UtilConstants.StringType)) ||
|
||||
&& ((ec.Length != dc.Length && !UtilMethods.GetUnderType(ec.PropertyInfo).IsEnum() && UtilMethods.GetUnderType(ec.PropertyInfo).IsIn(UtilConstants.StringType)) ||
|
||||
ec.IsNullable != dc.IsNullable ||
|
||||
IsSamgeType(ec, dc)))).ToList();
|
||||
var renameColumns = entityColumns
|
||||
@@ -212,7 +212,7 @@ namespace SqlSugar
|
||||
}
|
||||
protected virtual DbColumnInfo EntityColumnToDbColumn(EntityInfo entityInfo, string tableName, EntityColumnInfo item)
|
||||
{
|
||||
var propertyType = PubMethod.GetUnderType(item.PropertyInfo);
|
||||
var propertyType = UtilMethods.GetUnderType(item.PropertyInfo);
|
||||
var result = new DbColumnInfo()
|
||||
{
|
||||
TableId = entityInfo.Columns.IndexOf(item),
|
||||
@@ -246,7 +246,7 @@ namespace SqlSugar
|
||||
{
|
||||
return ec.DataType != dc.DataType;
|
||||
}
|
||||
var propertyType = PubMethod.GetUnderType(ec.PropertyInfo);
|
||||
var propertyType = UtilMethods.GetUnderType(ec.PropertyInfo);
|
||||
var properyTypeName = string.Empty;
|
||||
if (propertyType.IsEnum())
|
||||
{
|
||||
|
@@ -135,7 +135,7 @@ namespace SqlSugar
|
||||
}
|
||||
else
|
||||
{
|
||||
reval.Add((T)Convert.ChangeType(re.GetValue(0),PubMethod.GetUnderType(type)));
|
||||
reval.Add((T)Convert.ChangeType(re.GetValue(0),UtilMethods.GetUnderType(type)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -168,7 +168,7 @@ namespace SqlSugar
|
||||
IDbBind bind = Context.Ado.DbBind;
|
||||
bool isNullableType = false;
|
||||
MethodInfo method = null;
|
||||
Type bindPropertyType = PubMethod.GetUnderType(bindProperty, ref isNullableType);
|
||||
Type bindPropertyType = UtilMethods.GetUnderType(bindProperty, ref isNullableType);
|
||||
string dbTypeName = DataRecord.GetDataTypeName(ordinal);
|
||||
if (Regex.IsMatch(dbTypeName, @"\(.+\)"))
|
||||
{
|
||||
@@ -299,7 +299,7 @@ namespace SqlSugar
|
||||
var isAny = invalidTypes.Contains(bindProperyTypeName);
|
||||
if (isAny)
|
||||
{
|
||||
throw new SqlSugarException(string.Format("{0} can't convert {1} to {2}", propertyName, validPropertyType, bindProperyTypeName));
|
||||
throw new UtilExceptions(string.Format("{0} can't convert {1} to {2}", propertyName, validPropertyType, bindProperyTypeName));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
@@ -189,7 +189,7 @@ namespace SqlSugar
|
||||
#region Sqlite Extensions
|
||||
public static Nullable<T> GetSqliteTypeNull<T>(this IDataReader dr, int i) where T : struct
|
||||
{
|
||||
var type = PubMethod.GetUnderType(typeof(T));
|
||||
var type = UtilMethods.GetUnderType(typeof(T));
|
||||
if (dr.IsDBNull(i))
|
||||
{
|
||||
return null;
|
||||
|
@@ -174,7 +174,7 @@ namespace SqlSugar
|
||||
Value = column.PropertyInfo.GetValue(item, null),
|
||||
DbColumnName = GetDbColumnName(column.PropertyName),
|
||||
PropertyName = column.PropertyName,
|
||||
PropertyType = PubMethod.GetUnderType(column.PropertyInfo),
|
||||
PropertyType = UtilMethods.GetUnderType(column.PropertyInfo),
|
||||
TableId = i
|
||||
};
|
||||
if (columnInfo.PropertyType.IsEnum())
|
||||
|
@@ -23,7 +23,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
_WhereInfos = PubMethod.IsNullReturnNew(_WhereInfos);
|
||||
_WhereInfos = UtilMethods.IsNullReturnNew(_WhereInfos);
|
||||
return _WhereInfos;
|
||||
}
|
||||
set { _WhereInfos = value; }
|
||||
|
@@ -53,7 +53,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
_EasyJoinInfos = PubMethod.IsNullReturnNew(_EasyJoinInfos);
|
||||
_EasyJoinInfos = UtilMethods.IsNullReturnNew(_EasyJoinInfos);
|
||||
return _EasyJoinInfos;
|
||||
}
|
||||
set { _EasyJoinInfos = value; }
|
||||
@@ -62,7 +62,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
_JoinQueryInfos = PubMethod.IsNullReturnNew(_JoinQueryInfos);
|
||||
_JoinQueryInfos = UtilMethods.IsNullReturnNew(_JoinQueryInfos);
|
||||
return _JoinQueryInfos;
|
||||
}
|
||||
set { _JoinQueryInfos = value; }
|
||||
@@ -72,7 +72,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
_WhereInfos = PubMethod.IsNullReturnNew(_WhereInfos);
|
||||
_WhereInfos = UtilMethods.IsNullReturnNew(_WhereInfos);
|
||||
return _WhereInfos;
|
||||
}
|
||||
set { _WhereInfos = value; }
|
||||
|
@@ -20,7 +20,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
base._SqlQueryBuilder = PubMethod.IsNullReturnNew(base._SqlQueryBuilder);
|
||||
base._SqlQueryBuilder = UtilMethods.IsNullReturnNew(base._SqlQueryBuilder);
|
||||
return base._SqlQueryBuilder;
|
||||
}
|
||||
set { base._SqlQueryBuilder = value; }
|
||||
|
@@ -41,7 +41,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
_Sql = PubMethod.IsNullReturnNew(_Sql);
|
||||
_Sql = UtilMethods.IsNullReturnNew(_Sql);
|
||||
return _Sql;
|
||||
}
|
||||
set
|
||||
@@ -60,7 +60,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
_Parameters = PubMethod.IsNullReturnNew(_Parameters);
|
||||
_Parameters = UtilMethods.IsNullReturnNew(_Parameters);
|
||||
return _Parameters;
|
||||
}
|
||||
set
|
||||
|
@@ -179,7 +179,7 @@ namespace SqlSugar
|
||||
Value = column.PropertyInfo.GetValue(item, null),
|
||||
DbColumnName = GetDbColumnName(column.PropertyName),
|
||||
PropertyName = column.PropertyName,
|
||||
PropertyType = PubMethod.GetUnderType(column.PropertyInfo),
|
||||
PropertyType = UtilMethods.GetUnderType(column.PropertyInfo),
|
||||
TableId = i
|
||||
};
|
||||
if (columnInfo.PropertyType.IsEnum())
|
||||
|
@@ -26,7 +26,7 @@ namespace SqlSugar
|
||||
{
|
||||
var result = new DbColumnInfo()
|
||||
{
|
||||
DataType = this.Context.Ado.DbBind.GetDbTypeName(PubMethod.GetUnderType(item.PropertyInfo).Name),
|
||||
DataType = this.Context.Ado.DbBind.GetDbTypeName(UtilMethods.GetUnderType(item.PropertyInfo).Name),
|
||||
TableId = entityInfo.Columns.IndexOf(item),
|
||||
DbColumnName = item.DbColumnName.IsValuable() ? item.DbColumnName : item.PropertyName,
|
||||
IsPrimarykey = item.IsPrimarykey,
|
||||
|
@@ -45,7 +45,7 @@ namespace SqlSugar
|
||||
{
|
||||
var result = new DbColumnInfo()
|
||||
{
|
||||
DataType = this.Context.Ado.DbBind.GetDbTypeName(PubMethod.GetUnderType(item.PropertyInfo).Name),
|
||||
DataType = this.Context.Ado.DbBind.GetDbTypeName(UtilMethods.GetUnderType(item.PropertyInfo).Name),
|
||||
TableId = entityInfo.Columns.IndexOf(item),
|
||||
DbColumnName = item.DbColumnName.IsValuable() ? item.DbColumnName : item.PropertyName,
|
||||
IsPrimarykey = item.IsPrimarykey,
|
||||
|
@@ -140,9 +140,9 @@
|
||||
<Compile Include="Utilities\ErrorMessage.cs" />
|
||||
<Compile Include="Utilities\IsWhatExtensions.cs" />
|
||||
<Compile Include="Utilities\UtilConstants.cs" />
|
||||
<Compile Include="Utilities\UtilsConvert.cs" />
|
||||
<Compile Include="Utilities\PubMethod.cs" />
|
||||
<Compile Include="Utilities\SqlException.cs" />
|
||||
<Compile Include="Utilities\UtilConvert.cs" />
|
||||
<Compile Include="Utilities\UtilMethods.cs" />
|
||||
<Compile Include="Utilities\UtilExceptions.cs" />
|
||||
<Compile Include="Infrastructure\RewritableMethods.cs" />
|
||||
<Compile Include="Realization\SqlServer\CodeFirst\SqlServerCodeFirst.cs" />
|
||||
<Compile Include="Realization\SqlServer\SqlBuilder\SqlServerUpdateBuilder.cs" />
|
||||
|
@@ -9,31 +9,31 @@ namespace SqlSugar
|
||||
public static void ThrowNotSupportedException(string message)
|
||||
{
|
||||
message = message.IsNullOrEmpty() ? new NotSupportedException().Message : message;
|
||||
throw new SqlSugarException("SqlSugarException.NotSupportedException:" + message);
|
||||
throw new UtilExceptions("SqlSugarException.NotSupportedException:" + message);
|
||||
}
|
||||
|
||||
public static void ConnectionConfig(ConnectionConfig config)
|
||||
{
|
||||
if (config == null || config.ConnectionString.IsNullOrEmpty() || config.DbType.IsNullOrEmpty())
|
||||
{
|
||||
throw new SqlSugarException("SqlSugarException.ArgumentNullException:" + ErrorMessage.ConnectionConfigIsNull);
|
||||
throw new UtilExceptions("SqlSugarException.ArgumentNullException:" + ErrorMessage.ConnectionConfigIsNull);
|
||||
}
|
||||
}
|
||||
public static void ArgumentNullException(object checkObj, string message)
|
||||
{
|
||||
if (checkObj == null)
|
||||
throw new SqlSugarException("SqlSugarException.ArgumentNullException:" + message);
|
||||
throw new UtilExceptions("SqlSugarException.ArgumentNullException:" + message);
|
||||
}
|
||||
public static void ArgumentNullException(object [] checkObj, string message)
|
||||
{
|
||||
if (checkObj == null|| checkObj.Length==0)
|
||||
throw new SqlSugarException("SqlSugarException.ArgumentNullException:" + message);
|
||||
throw new UtilExceptions("SqlSugarException.ArgumentNullException:" + message);
|
||||
}
|
||||
|
||||
public static void Exception(bool isException, string message, params string[] args)
|
||||
{
|
||||
if (isException)
|
||||
throw new SqlSugarException(string.Format(message, args));
|
||||
throw new UtilExceptions(string.Format(message, args));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
namespace SqlSugar
|
||||
{
|
||||
public static class UtilsConvert
|
||||
public static class UtilConvert
|
||||
{
|
||||
public static int ObjToInt(this object thisValue)
|
||||
{
|
@@ -5,18 +5,18 @@ using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class SqlSugarException : Exception
|
||||
public class UtilExceptions : Exception
|
||||
{
|
||||
public SqlSugarException(string message)
|
||||
public UtilExceptions(string message)
|
||||
: base(message){}
|
||||
|
||||
public SqlSugarException(SqlSugarClient context,string message, string sql)
|
||||
public UtilExceptions(SqlSugarClient context,string message, string sql)
|
||||
: base(GetMessage(context, message, sql)) {}
|
||||
|
||||
public SqlSugarException(SqlSugarClient context, string message, string sql, object pars)
|
||||
public UtilExceptions(SqlSugarClient context, string message, string sql, object pars)
|
||||
: base(GetMessage(context,message, sql, pars)){}
|
||||
|
||||
public SqlSugarException(SqlSugarClient context, string message, object pars)
|
||||
public UtilExceptions(SqlSugarClient context, string message, object pars)
|
||||
: base(GetMessage(context,message, pars)){}
|
||||
|
||||
private static string GetMessage(SqlSugarClient context, string message, object pars)
|
@@ -7,7 +7,7 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class PubMethod
|
||||
public class UtilMethods
|
||||
{
|
||||
internal static Type GetUnderType(Type oldType)
|
||||
{
|
||||
@@ -36,7 +36,6 @@ namespace SqlSugar
|
||||
return unType != null;
|
||||
}
|
||||
|
||||
|
||||
internal static T IsNullReturnNew<T>(T returnObj) where T : new()
|
||||
{
|
||||
if (returnObj.IsNullOrEmpty())
|
Reference in New Issue
Block a user