Browse Source

Update Core

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
5a0d4b985a
  1. 15
      Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs
  2. 1
      Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs
  3. 1
      Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/EntityProvider/EntityProvider.cs
  4. 2
      Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  5. 5
      Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/SqlBuilderProvider/DeleteBuilder.cs
  6. 31
      Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Common/CacheManager.cs
  7. 15
      Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Common/RewritableMethods.cs
  8. 1
      Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Entities/EntityColumnInfo.cs
  9. 8
      Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs
  10. 2
      Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/Common/SugarParameter.cs
  11. 5
      Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Interface/IRewritableMethods.cs

15
Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs

@ -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 = item.DataType;
}
else if (propertyType.IsEnum())
{
result.DataType = this.Context.Ado.DbBind.GetDbTypeName(item.Length>9?PubConst.LongType.Name:PubConst.IntType.Name);
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())

1
Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs

@ -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");

1
Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/EntityProvider/EntityProvider.cs

@ -122,6 +122,7 @@ namespace SqlSugar
column.IsNullable = sugarColumn.IsNullable;
column.Length = sugarColumn.Length;
column.OldDbColumnName = sugarColumn.OldColumnName;
column.DataType = sugarColumn.ColumnDataType;
}
else
{

2
Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -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;

5
Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/SqlBuilderProvider/DeleteBuilder.cs

@ -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
}
}

31
Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Common/CacheManager.cs

@ -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();
}
}
}
}
}

15
Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Common/RewritableMethods.cs

@ -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)
{

1
Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Entities/EntityColumnInfo.cs

@ -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; }
}
}

8
Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs

@ -79,7 +79,13 @@ namespace SqlSugar
get { return _OldColumnName; }
set { _OldColumnName = value; }
}
private string _ColumnDataType;
public string ColumnDataType
{
get { return _ColumnDataType; }
set { _ColumnDataType = value; }
}
}
}

2
Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/Common/SugarParameter.cs

@ -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)
{

5
Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Interface/IRewritableMethods.cs

@ -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);
}
}

Loading…
Cancel
Save