mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-23 04:23:47 +08:00
Update Core
This commit is contained in:
@@ -80,6 +80,7 @@ namespace SqlSugar
|
||||
#region Check
|
||||
public virtual bool IsAnyTable(string tableName, bool isCache = true)
|
||||
{
|
||||
Check.Exception(string.IsNullOrEmpty(tableName), "IsAnyTable tableName is not null");
|
||||
tableName = this.SqlBuilder.GetNoTranslationColumnName(tableName);
|
||||
var tables = GetTableInfoList(isCache);
|
||||
if (tables == null) return false;
|
||||
|
@@ -146,7 +146,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
return "ORDER BY "+this.Builder.SqlDateNow+" ";
|
||||
return "ORDER BY " + this.Builder.SqlDateNow + " ";
|
||||
}
|
||||
}
|
||||
public virtual string OrderByTemplate
|
||||
@@ -216,7 +216,8 @@ namespace SqlSugar
|
||||
public virtual ExpressionResult GetExpressionValue(Expression expression, ResolveExpressType resolveType)
|
||||
{
|
||||
ILambdaExpressions resolveExpress = this.LambdaExpressions;
|
||||
if (resolveType.IsIn(ResolveExpressType.FieldSingle,ResolveExpressType.FieldMultiple,ResolveExpressType.SelectSingle, ResolveExpressType.SelectMultiple) &&(expression is LambdaExpression)&& (expression as LambdaExpression).Body is BinaryExpression) {
|
||||
if (resolveType.IsIn(ResolveExpressType.FieldSingle, ResolveExpressType.FieldMultiple, ResolveExpressType.SelectSingle, ResolveExpressType.SelectMultiple) && (expression is LambdaExpression) && (expression as LambdaExpression).Body is BinaryExpression)
|
||||
{
|
||||
resolveType = resolveType.IsIn(ResolveExpressType.SelectSingle, ResolveExpressType.FieldSingle) ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple;
|
||||
}
|
||||
this.LambdaExpressions.Clear();
|
||||
@@ -246,7 +247,8 @@ namespace SqlSugar
|
||||
this.Parameters.AddRange(resolveExpress.Parameters);
|
||||
var result = resolveExpress.Result;
|
||||
var isSingleTableHasSubquery = IsSingle() && resolveExpress.SingleTableNameSubqueryShortName.HasValue();
|
||||
if (isSingleTableHasSubquery) {
|
||||
if (isSingleTableHasSubquery)
|
||||
{
|
||||
Check.Exception(!string.IsNullOrEmpty(this.TableShortName) && resolveExpress.SingleTableNameSubqueryShortName != this.TableShortName, "{0} and {1} need same name");
|
||||
this.TableShortName = resolveExpress.SingleTableNameSubqueryShortName;
|
||||
}
|
||||
@@ -256,7 +258,7 @@ namespace SqlSugar
|
||||
{
|
||||
string oldOrderBy = this.OrderByValue;
|
||||
string externalOrderBy = oldOrderBy;
|
||||
var isIgnoreOrderBy = this.IsCount&&this.PartitionByValue.IsNullOrEmpty();
|
||||
var isIgnoreOrderBy = this.IsCount && this.PartitionByValue.IsNullOrEmpty();
|
||||
AppendFilter();
|
||||
sql = new StringBuilder();
|
||||
if (this.OrderByValue == null && (Skip != null || Take != null)) this.OrderByValue = " ORDER BY GetDate() ";
|
||||
@@ -271,7 +273,7 @@ namespace SqlSugar
|
||||
if (isIgnoreOrderBy) { orderByValue = null; }
|
||||
sql.AppendFormat(SqlTemplate, GetSelectValue, GetTableNameString, GetWhereValueString, groupByValue, orderByValue);
|
||||
sql.Replace(UtilConstants.ReplaceKey, isRowNumber ? (isIgnoreOrderBy ? null : rowNumberString) : null);
|
||||
if (isIgnoreOrderBy) { this.OrderByValue = oldOrderBy; return sql.ToString(); }
|
||||
if (isIgnoreOrderBy) { this.OrderByValue = oldOrderBy; return sql.ToString(); }
|
||||
var result = ToPageSql(sql.ToString(), this.Take, this.Skip);
|
||||
if (ExternalPageIndex > 0)
|
||||
{
|
||||
@@ -294,7 +296,7 @@ namespace SqlSugar
|
||||
foreach (var item in gobalFilterList.Where(it => it.IsJoinQuery == !IsSingle()))
|
||||
{
|
||||
var filterResult = item.FilterValue(this.Context);
|
||||
WhereInfos.Add(this.Builder.AppendWhereOrAnd(this.WhereInfos.IsNullOrEmpty(), filterResult.Sql+UtilConstants.Space));
|
||||
WhereInfos.Add(this.Builder.AppendWhereOrAnd(this.WhereInfos.IsNullOrEmpty(), filterResult.Sql + UtilConstants.Space));
|
||||
var filterParamters = this.Context.Ado.GetParameters(filterResult.Parameters);
|
||||
if (filterParamters.HasValue())
|
||||
{
|
||||
@@ -339,18 +341,18 @@ namespace SqlSugar
|
||||
public virtual string ToPageSql2(string sql, int? pageIndex, int? pageSize, bool isExternal = false)
|
||||
{
|
||||
string temp = isExternal ? ExternalPageTempalte : PageTempalte;
|
||||
return string.Format(temp, sql.ToString(), (pageIndex - 1) * pageSize+1, pageIndex * pageSize);
|
||||
return string.Format(temp, sql.ToString(), (pageIndex - 1) * pageSize + 1, pageIndex * pageSize);
|
||||
}
|
||||
|
||||
public virtual string GetSelectByItems(List<KeyValuePair<string, object>> items)
|
||||
{
|
||||
var array = items.Select(it => {
|
||||
dynamic dynamicObj = this.Context.Utilities.DeserializeObject<dynamic>(this.Context.Utilities.SerializeObject(it.Value));
|
||||
var dbName =Builder.GetTranslationColumnName( (string)(dynamicObj.dbName));
|
||||
var dbName = Builder.GetTranslationColumnName((string)(dynamicObj.dbName));
|
||||
var asName = Builder.GetTranslationColumnName((string)(dynamicObj.asName));
|
||||
return string.Format("{0}.{1} AS {2}",it.Key,dbName,asName);
|
||||
return string.Format("{0}.{1} AS {2}", it.Key, dbName, asName);
|
||||
});
|
||||
return string.Join(",",array);
|
||||
return string.Join(",", array);
|
||||
}
|
||||
|
||||
public virtual string ToJoinString(JoinQueryInfo joinInfo)
|
||||
@@ -359,7 +361,7 @@ namespace SqlSugar
|
||||
this.JoinTemplate,
|
||||
joinInfo.JoinType.ToString() + UtilConstants.Space,
|
||||
Builder.GetTranslationTableName(joinInfo.TableName) + UtilConstants.Space,
|
||||
joinInfo.ShortName + UtilConstants.Space + (TableWithString==SqlWith.Null?" ": TableWithString),
|
||||
joinInfo.ShortName + UtilConstants.Space + (TableWithString == SqlWith.Null ? " " : TableWithString),
|
||||
joinInfo.JoinWhere);
|
||||
}
|
||||
public virtual void Clear()
|
||||
@@ -420,7 +422,7 @@ namespace SqlSugar
|
||||
}
|
||||
else
|
||||
{
|
||||
if (expression is LambdaExpression && (expression as LambdaExpression).Body is MethodCallExpression&&this.Context.CurrentConnectionConfig.DbType==DbType.SqlServer&&this.OrderByValue.HasValue())
|
||||
if (expression is LambdaExpression && (expression as LambdaExpression).Body is MethodCallExpression && this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer && this.OrderByValue.HasValue())
|
||||
{
|
||||
result = result + " AS columnName";
|
||||
}
|
||||
@@ -441,7 +443,7 @@ namespace SqlSugar
|
||||
var columns = this.Context.EntityMaintenance.GetEntityInfo(this.EntityType).Columns.Where(it => !it.IsIgnore);
|
||||
if (this.IgnoreColumns.HasValue())
|
||||
{
|
||||
columns = columns.Where(c => !this.IgnoreColumns.Any(i=>c.PropertyName.Equals(i,StringComparison.CurrentCultureIgnoreCase)||c.DbColumnName.Equals(i,StringComparison.CurrentCultureIgnoreCase))).ToList();
|
||||
columns = columns.Where(c => !this.IgnoreColumns.Any(i => c.PropertyName.Equals(i, StringComparison.CurrentCultureIgnoreCase) || c.DbColumnName.Equals(i, StringComparison.CurrentCultureIgnoreCase))).ToList();
|
||||
}
|
||||
result = string.Join(",", columns.Select(it => pre + Builder.GetTranslationColumnName(it.EntityName, it.PropertyName)));
|
||||
}
|
||||
@@ -488,7 +490,7 @@ namespace SqlSugar
|
||||
{
|
||||
result += (TableShortName + UtilConstants.Space);
|
||||
}
|
||||
if (this.TableWithString.HasValue()&&this.TableWithString!= SqlWith.Null)
|
||||
if (this.TableWithString.HasValue() && this.TableWithString != SqlWith.Null)
|
||||
{
|
||||
result += TableWithString + UtilConstants.Space;
|
||||
}
|
||||
@@ -516,7 +518,7 @@ namespace SqlSugar
|
||||
get
|
||||
{
|
||||
if (this.OrderByValue == null) return null;
|
||||
if (IsCount&&this.PartitionByValue.IsNullOrEmpty()) return null;
|
||||
if (IsCount && this.PartitionByValue.IsNullOrEmpty()) return null;
|
||||
else
|
||||
{
|
||||
return this.OrderByValue;
|
||||
@@ -528,7 +530,7 @@ namespace SqlSugar
|
||||
get
|
||||
{
|
||||
if (this.GroupByValue == null) return null;
|
||||
if (this.GroupByValue.Last() != ' ' )
|
||||
if (this.GroupByValue.Last() != ' ')
|
||||
{
|
||||
return this.GroupByValue + UtilConstants.Space;
|
||||
}
|
||||
@@ -546,11 +548,12 @@ namespace SqlSugar
|
||||
|
||||
public void CheckExpression(Expression expression, string methodName)
|
||||
{
|
||||
if (IsSingle() == false&& this.JoinExpression!=null)
|
||||
if (IsSingle() == false && this.JoinExpression != null)
|
||||
{
|
||||
var jsoinParameters = (this.JoinExpression as LambdaExpression).Parameters;
|
||||
var currentParametres = (expression as LambdaExpression).Parameters;
|
||||
if ((expression as LambdaExpression).Body.ToString() == "True") {
|
||||
if ((expression as LambdaExpression).Body.ToString() == "True")
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (currentParametres != null && currentParametres.Count > 0)
|
||||
|
@@ -55,7 +55,7 @@ namespace SqlSugar
|
||||
{
|
||||
if (value == null) return value;
|
||||
var type = value.GetType();
|
||||
if (type.IsEnum()&& type != typeof(DateType)&& type!=typeof(JoinType)&&type!=typeof(OrderByType)) return Convert.ToInt64(value);
|
||||
if (type.IsEnum() && type != typeof(DateType) && type != typeof(JoinType) && type != typeof(OrderByType)) return Convert.ToInt64(value);
|
||||
else
|
||||
return value;
|
||||
}
|
||||
@@ -77,7 +77,7 @@ namespace SqlSugar
|
||||
}
|
||||
public static bool IsLogicOperator(string operatorValue)
|
||||
{
|
||||
return operatorValue == "&&" || operatorValue == "||"||operatorValue == "AND" || operatorValue == "OR";
|
||||
return operatorValue == "&&" || operatorValue == "||" || operatorValue == "AND" || operatorValue == "OR";
|
||||
}
|
||||
|
||||
public static bool IsLogicOperator(Expression expression)
|
||||
@@ -133,7 +133,8 @@ namespace SqlSugar
|
||||
}
|
||||
// fetch the root object reference:
|
||||
var constExpr = expression as ConstantExpression;
|
||||
if (constExpr == null) {
|
||||
if (constExpr == null)
|
||||
{
|
||||
return DynamicInvoke(rootExpression);
|
||||
}
|
||||
object objReference = constExpr.Value;
|
||||
@@ -146,7 +147,7 @@ namespace SqlSugar
|
||||
var objProp = objReference.GetType().GetProperty(mi.Name);
|
||||
if (objProp == null)
|
||||
{
|
||||
objReference = DynamicInvoke(expression, rootExpression==null?memberExpr: rootExpression);
|
||||
objReference = DynamicInvoke(expression, rootExpression == null ? memberExpr : rootExpression);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -158,7 +159,7 @@ namespace SqlSugar
|
||||
var objField = objReference.GetType().GetField(mi.Name);
|
||||
if (objField == null)
|
||||
{
|
||||
objReference = DynamicInvoke(expression, rootExpression==null?memberExpr: rootExpression);
|
||||
objReference = DynamicInvoke(expression, rootExpression == null ? memberExpr : rootExpression);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -205,7 +206,7 @@ namespace SqlSugar
|
||||
public static bool IsConstExpression(MemberExpression memberExpr)
|
||||
{
|
||||
var result = false;
|
||||
while (memberExpr!=null&&memberExpr.Expression != null)
|
||||
while (memberExpr != null && memberExpr.Expression != null)
|
||||
{
|
||||
var isConst = memberExpr.Expression is ConstantExpression;
|
||||
if (isConst)
|
||||
@@ -248,10 +249,10 @@ namespace SqlSugar
|
||||
return reval;
|
||||
}
|
||||
|
||||
public static object DynamicInvoke(Expression expression,MemberExpression memberExpression=null)
|
||||
public static object DynamicInvoke(Expression expression, MemberExpression memberExpression = null)
|
||||
{
|
||||
object value = Expression.Lambda(expression).Compile().DynamicInvoke();
|
||||
if (value != null && value.GetType().IsClass() && value.GetType() != UtilConstants.StringType&& memberExpression!=null)
|
||||
if (value != null && value.GetType().IsClass() && value.GetType() != UtilConstants.StringType && memberExpression != null)
|
||||
{
|
||||
value = Expression.Lambda(memberExpression).Compile().DynamicInvoke();
|
||||
}
|
||||
|
@@ -536,6 +536,37 @@ namespace SqlSugar
|
||||
}
|
||||
return this.DeserializeObject<List<T>>(this.SerializeObject(deserializeObject));
|
||||
}
|
||||
public DataTable ListToDataTable<T>(List<T> list)
|
||||
{
|
||||
DataTable result = new DataTable();
|
||||
if (list.Count > 0)
|
||||
{
|
||||
PropertyInfo[] propertys = list[0].GetType().GetProperties();
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
//获取类型
|
||||
Type colType = pi.PropertyType;
|
||||
//当类型为Nullable<>时
|
||||
if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable<>)))
|
||||
{
|
||||
colType = colType.GetGenericArguments()[0];
|
||||
}
|
||||
result.Columns.Add(pi.Name, colType);
|
||||
}
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
ArrayList tempList = new ArrayList();
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
object obj = pi.GetValue(list[i], null);
|
||||
tempList.Add(obj);
|
||||
}
|
||||
object[] array = tempList.ToArray();
|
||||
result.LoadDataRow(array, true);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public Dictionary<string, object> DataTableToDictionary(DataTable table)
|
||||
{
|
||||
return table.Rows.Cast<DataRow>().ToDictionary(x => x[0].ToString(), x => x[1]);
|
||||
|
@@ -27,6 +27,7 @@ namespace SqlSugar
|
||||
SqlSugarProvider CopyContext(bool isCopyEvents = false);
|
||||
dynamic DataTableToDynamic(DataTable table);
|
||||
List<T> DataTableToList<T>(DataTable table);
|
||||
DataTable ListToDataTable<T>(List<T> list);
|
||||
Dictionary<string, object> DataTableToDictionary(DataTable table);
|
||||
ICacheService GetReflectionInoCacheInstance();
|
||||
void RemoveCacheAll();
|
||||
|
@@ -108,6 +108,7 @@ namespace SqlSugar
|
||||
new KeyValuePair<string, CSharpDataType>("char",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("nchar",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("clob",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("text",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("long",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("nclob",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("rowid",CSharpDataType.@string),
|
||||
|
@@ -426,7 +426,7 @@ namespace SqlSugar
|
||||
var comments = this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey,
|
||||
() =>
|
||||
{
|
||||
string sql = "SELECT TVNAME AS TableName, COLNAME,COMMENT$ AS ColumnDescription from SYSCOLUMNCOMMENTS WHERE TVNAME='" + tableName.ToUpper() + "' ORDER BY TVNAME";
|
||||
string sql = "SELECT TVNAME AS TableName, COLNAME as DbColumnName ,COMMENT$ AS ColumnDescription from SYSCOLUMNCOMMENTS WHERE TVNAME='" + tableName.ToUpper() + "' ORDER BY TVNAME";
|
||||
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
|
||||
this.Context.Ado.IsEnableLogEvent = false;
|
||||
var pks = this.Context.Ado.SqlQuery<DbColumnInfo>(sql);
|
||||
|
@@ -99,7 +99,7 @@ namespace SqlSugar
|
||||
sqlParameter.DbType = parameter.DbType;
|
||||
if (parameter.Direction == 0)
|
||||
{
|
||||
parameter.Direction= ParameterDirection.Input; ;
|
||||
parameter.Direction = ParameterDirection.Input;
|
||||
}
|
||||
sqlParameter.Direction = parameter.Direction;
|
||||
//if (sqlParameter.Direction == 0)
|
||||
@@ -107,7 +107,7 @@ namespace SqlSugar
|
||||
// sqlParameter.Direction = ParameterDirection.Input;
|
||||
//}
|
||||
result[index] = sqlParameter;
|
||||
if (sqlParameter.Direction.IsIn(ParameterDirection.Output, ParameterDirection.InputOutput,ParameterDirection.ReturnValue))
|
||||
if (sqlParameter.Direction.IsIn(ParameterDirection.Output, ParameterDirection.InputOutput, ParameterDirection.ReturnValue))
|
||||
{
|
||||
if (this.OutputParameters == null) this.OutputParameters = new List<IDataParameter>();
|
||||
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName);
|
||||
|
@@ -230,7 +230,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
return "alter table {0} rename to {1}";
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -53,7 +53,7 @@ namespace SqlSugar
|
||||
public Guid ContextID { get { return this.Context.ContextID; } set { this.Context.ContextID = value; } }
|
||||
|
||||
|
||||
public MappingTableList MappingTables { get { return _MappingTables; } set { _MappingTables = value; } }
|
||||
public MappingTableList MappingTables { get { return _MappingTables; } set { _MappingTables = value; } }
|
||||
public MappingColumnList MappingColumns { get { return _MappingColumns; } set { _MappingColumns = value; } }
|
||||
public IgnoreColumnList IgnoreColumns { get { return _IgnoreColumns; } set { _IgnoreColumns = value; } }
|
||||
public IgnoreColumnList IgnoreInsertColumns { get { return _IgnoreInsertColumns; } set { _IgnoreInsertColumns = value; } }
|
||||
@@ -308,14 +308,14 @@ namespace SqlSugar
|
||||
}
|
||||
|
||||
|
||||
public ISugarQueryable<T, T2, T3> Queryable<T, T2,T3>(ISugarQueryable<T> joinQueryable1, ISugarQueryable<T2> joinQueryable2, ISugarQueryable<T3> joinQueryable3,
|
||||
JoinType joinType1, Expression<Func<T, T2,T3, bool>> joinExpression1,
|
||||
JoinType joinType2, Expression<Func<T, T2,T3, bool>> joinExpression2)
|
||||
public ISugarQueryable<T, T2, T3> Queryable<T, T2, T3>(ISugarQueryable<T> joinQueryable1, ISugarQueryable<T2> joinQueryable2, ISugarQueryable<T3> joinQueryable3,
|
||||
JoinType joinType1, Expression<Func<T, T2, T3, bool>> joinExpression1,
|
||||
JoinType joinType2, Expression<Func<T, T2, T3, bool>> joinExpression2)
|
||||
where T : class, new()
|
||||
where T2 : class, new()
|
||||
where T3 : class, new()
|
||||
{
|
||||
return this.Context.Queryable(joinQueryable1, joinQueryable2,joinQueryable3, joinType1, joinExpression1,joinType2,joinExpression2).With(SqlWith.Null);
|
||||
return this.Context.Queryable(joinQueryable1, joinQueryable2, joinQueryable3, joinType1, joinExpression1, joinType2, joinExpression2).With(SqlWith.Null);
|
||||
}
|
||||
|
||||
|
||||
@@ -539,7 +539,7 @@ namespace SqlSugar
|
||||
public IDbFirst DbFirst => this.Context.DbFirst;
|
||||
public IDbMaintenance DbMaintenance => this.Context.DbMaintenance;
|
||||
public EntityMaintenance EntityMaintenance { get { return this.Context.EntityMaintenance; } set { this.Context.EntityMaintenance = value; } }
|
||||
public QueryFilterProvider QueryFilter { get { return this.Context.QueryFilter; }set { this.Context.QueryFilter = value; } }
|
||||
public QueryFilterProvider QueryFilter { get { return this.Context.QueryFilter; } set { this.Context.QueryFilter = value; } }
|
||||
#endregion
|
||||
|
||||
#region TenantManager
|
||||
|
Reference in New Issue
Block a user