mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-10-15 18:55:07 +08:00
Update Core
This commit is contained in:
@@ -22,6 +22,7 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual void InitTables(Type entityType)
|
||||
{
|
||||
this.Context.RewritableMethods.RemoveCacheAll();
|
||||
if (!this.Context.DbMaintenance.IsAnySystemTablePermissions())
|
||||
{
|
||||
Check.Exception(true, "Dbfirst and Codefirst requires system table permissions");
|
||||
@@ -112,7 +113,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(PubConst.StringType)) ||
|
||||
&& ((ec.Length != dc.Length && !PubMethod.GetUnderType(ec.PropertyInfo).IsEnum() && PubMethod.GetUnderType(ec.PropertyInfo).IsIn(PubConst.StringType)) ||
|
||||
ec.IsNullable != dc.IsNullable ||
|
||||
IsSamgeType(ec, dc)))).ToList();
|
||||
var renameColumns = entityColumns
|
||||
@@ -222,9 +223,13 @@ namespace SqlSugar
|
||||
ColumnDescription = item.ColumnDescription,
|
||||
Length = item.Length
|
||||
};
|
||||
if (propertyType.IsEnum())
|
||||
if (!string.IsNullOrEmpty(item.DataType))
|
||||
{
|
||||
result.DataType = this.Context.Ado.DbBind.GetDbTypeName(item.Length>9?PubConst.LongType.Name:PubConst.IntType.Name);
|
||||
result.DataType = item.DataType;
|
||||
}
|
||||
else if (propertyType.IsEnum())
|
||||
{
|
||||
result.DataType = this.Context.Ado.DbBind.GetDbTypeName(item.Length > 9 ? PubConst.LongType.Name : PubConst.IntType.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -235,6 +240,10 @@ namespace SqlSugar
|
||||
|
||||
protected virtual bool IsSamgeType(EntityColumnInfo ec, DbColumnInfo dc)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(ec.DataType))
|
||||
{
|
||||
return ec.DataType != dc.DataType;
|
||||
}
|
||||
var propertyType = PubMethod.GetUnderType(ec.PropertyInfo);
|
||||
var properyTypeName = string.Empty;
|
||||
if (propertyType.IsEnum())
|
||||
|
@@ -39,6 +39,7 @@ namespace SqlSugar
|
||||
|
||||
public void Init()
|
||||
{
|
||||
this.Context.RewritableMethods.RemoveCacheAll();
|
||||
if (!this.Context.DbMaintenance.IsAnySystemTablePermissions())
|
||||
{
|
||||
Check.Exception(true, "Dbfirst and Codefirst requires system table permissions");
|
||||
|
@@ -122,6 +122,7 @@ namespace SqlSugar
|
||||
column.IsNullable = sugarColumn.IsNullable;
|
||||
column.Length = sugarColumn.Length;
|
||||
column.OldDbColumnName = sugarColumn.OldColumnName;
|
||||
column.DataType = sugarColumn.ColumnDataType;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -123,7 +123,7 @@ namespace SqlSugar
|
||||
public virtual ISugarQueryable<T> Where<T2>(string whereString, object whereObj = null)
|
||||
{
|
||||
var whereValue = QueryBuilder.WhereInfos;
|
||||
whereValue.Add(SqlBuilder.AppendWhereOrAnd(whereValue.Count == 0, whereString));
|
||||
whereValue.Add(SqlBuilder.AppendWhereOrAnd(whereValue.Count == 0, whereString+PubConst.Space));
|
||||
if (whereObj != null)
|
||||
QueryBuilder.Parameters.AddRange(Context.Ado.GetParameters(whereObj));
|
||||
return this;
|
||||
|
@@ -125,11 +125,12 @@ namespace SqlSugar
|
||||
resolveExpress.MappingTables = Context.MappingTables;
|
||||
resolveExpress.IgnoreComumnList = Context.IgnoreColumns;
|
||||
resolveExpress.Resolve(expression, resolveType);
|
||||
this.Parameters = new List<SugarParameter>();
|
||||
if (this.Parameters == null)
|
||||
this.Parameters = new List<SugarParameter>();
|
||||
this.Parameters.AddRange(resolveExpress.Parameters);
|
||||
var reval = resolveExpress.Result;
|
||||
return reval;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@@ -39,7 +39,11 @@ namespace SqlSugar
|
||||
if (_instance == null)
|
||||
lock (_instanceLock)
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new CacheManager<V>();
|
||||
Action addItem =()=> { CacheManager<V>.GetInstance().RemoveAllCache(); };
|
||||
CacheManager.Add(addItem);
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
@@ -59,6 +63,14 @@ namespace SqlSugar
|
||||
this.InstanceCache.TryRemove(key, out val);
|
||||
}
|
||||
|
||||
public void RemoveAllCache()
|
||||
{
|
||||
foreach (var key in GetAllKey())
|
||||
{
|
||||
this.Remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetAllKey()
|
||||
{
|
||||
return this.InstanceCache.Keys;
|
||||
@@ -84,4 +96,23 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
}
|
||||
public static class CacheManager
|
||||
{
|
||||
private static List<Action> removeActions = new List<Action>();
|
||||
internal static void Add(Action removeAction)
|
||||
{
|
||||
removeActions.Add(removeAction);
|
||||
}
|
||||
|
||||
public static void RemoveAllCache()
|
||||
{
|
||||
lock (removeActions)
|
||||
{
|
||||
foreach (var item in removeActions)
|
||||
{
|
||||
item();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -183,6 +183,21 @@ namespace SqlSugar
|
||||
return CacheManager<T>.GetInstance();
|
||||
}
|
||||
|
||||
public void RemoveCacheAll()
|
||||
{
|
||||
CacheManager.RemoveAllCache();
|
||||
}
|
||||
|
||||
public void RemoveCacheAll<T>()
|
||||
{
|
||||
CacheManager<T>.GetInstance().RemoveAllCache();
|
||||
}
|
||||
|
||||
public void RemoveCache<T>(string key)
|
||||
{
|
||||
CacheManager<T>.GetInstance().Remove(key);
|
||||
}
|
||||
|
||||
#region Private Methods
|
||||
private Dictionary<string, object> DataReaderToDynamicList_Part<T>(Dictionary<string, object> readerValues, PropertyInfo item, List<T> reval)
|
||||
{
|
||||
|
@@ -22,5 +22,6 @@ namespace SqlSugar
|
||||
public string EntityName { get; set; }
|
||||
public string DbTableName { get; set; }
|
||||
public bool IsIgnore { get; set; }
|
||||
public string DataType { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -79,7 +79,13 @@ namespace SqlSugar
|
||||
get { return _OldColumnName; }
|
||||
set { _OldColumnName = value; }
|
||||
}
|
||||
|
||||
|
||||
private string _ColumnDataType;
|
||||
public string ColumnDataType
|
||||
{
|
||||
get { return _ColumnDataType; }
|
||||
set { _ColumnDataType = value; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -49,7 +49,7 @@ namespace SqlSugar
|
||||
}
|
||||
else if (type == PubConst.DateType)
|
||||
{
|
||||
this.DbType = System.Data.DbType.Date;
|
||||
this.DbType = System.Data.DbType.DateTime;
|
||||
}
|
||||
else if (type == PubConst.DobType)
|
||||
{
|
||||
|
@@ -17,6 +17,9 @@ namespace SqlSugar
|
||||
T TranslateCopy<T>(T sourceObject);
|
||||
dynamic DataTableToDynamic(DataTable table);
|
||||
ICacheManager<T> GetCacheInstance<T>();
|
||||
|
||||
void RemoveCacheAll();
|
||||
void RemoveCacheAll<T>();
|
||||
void RemoveCache<T>(string key);
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user