Update Core

This commit is contained in:
sunkaixuan 2017-08-28 02:31:02 +08:00
parent d4d04b4193
commit d9544271ee
69 changed files with 739 additions and 457 deletions

View File

@ -16,21 +16,17 @@ namespace SqlSugar
protected IDbMaintenance _DbMaintenance;
protected IDbConnection _DbConnection;
protected virtual SugarParameter[] GetParameters(object parameters, PropertyInfo[] propertyInfo,string sqlParameterKeyWord)
protected virtual SugarParameter[] GetParameters(object parameters, PropertyInfo[] propertyInfo, string sqlParameterKeyWord)
{
List<SugarParameter> result = new List<SugarParameter>();
if (parameters != null)
{
var entityType = parameters.GetType();
var isDictionary = entityType.IsIn(PubConst.DicArraySO, PubConst.DicArraySS);
var isDictionary = entityType.IsIn(UtilConstants.DicArraySO, UtilConstants.DicArraySS);
if (isDictionary)
{
DictionaryToParameters(parameters, sqlParameterKeyWord, result, entityType);
}
else
{
ProperyToParameter(parameters, propertyInfo, sqlParameterKeyWord, result, entityType);
}
}
return result.ToArray();
}
@ -38,20 +34,15 @@ namespace SqlSugar
{
PropertyInfo[] properties = null;
if (propertyInfo != null)
{
properties = propertyInfo;
}
else
{
properties = entityType.GetProperties();
}
foreach (PropertyInfo properyty in properties)
{
var value = properyty.GetValue(parameters, null);
if (properyty.PropertyType.IsEnum())
{
value = Convert.ToInt64(value);
}
if (value == null || value.Equals(DateTime.MinValue)) value = DBNull.Value;
if (properyty.Name.ToLower().Contains("hierarchyid"))
{
@ -69,7 +60,7 @@ namespace SqlSugar
}
protected void DictionaryToParameters(object parameters, string sqlParameterKeyWord, List<SugarParameter> listParams, Type entityType)
{
if (entityType == PubConst.DicArraySO)
if (entityType == UtilConstants.DicArraySO)
{
var dictionaryParameters = (Dictionary<string, object>)parameters;
var sugarParameters = dictionaryParameters.Select(it => new SugarParameter(sqlParameterKeyWord + it.Key, it.Value));

View File

@ -48,7 +48,7 @@ namespace SqlSugar
}
public virtual void InitTables(string entitiesNamespace)
{
var types = ReflectionCore.Load(entitiesNamespace).GetTypes();
var types = Assembly.Load(entitiesNamespace).GetTypes();
InitTables(types);
}
public virtual void InitTables(params string[] entitiesNamespaces)
@ -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(PubConst.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),
@ -223,7 +223,8 @@ namespace SqlSugar
IsNullable = item.IsNullable,
DefaultValue = item.DefaultValue,
ColumnDescription = item.ColumnDescription,
Length = item.Length
Length = item.Length,
DecimalDigits=item.DecimalDigits
};
if (!string.IsNullOrEmpty(item.DataType))
{
@ -231,7 +232,7 @@ namespace SqlSugar
}
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 ? UtilConstants.LongType.Name : UtilConstants.IntType.Name);
}
else
{
@ -246,11 +247,11 @@ 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())
{
properyTypeName = this.Context.Ado.DbBind.GetDbTypeName(ec.Length > 9 ? PubConst.LongType.Name : PubConst.IntType.Name);
properyTypeName = this.Context.Ado.DbBind.GetDbTypeName(ec.Length > 9 ? UtilConstants.LongType.Name : UtilConstants.IntType.Name);
}
else
{

View File

@ -45,32 +45,32 @@ namespace SqlSugar
{
while (re.Read())
{
if (PubConst.DicOO == type)
if (UtilConstants.DicOO == type)
{
var kv = new KeyValuePair<object, object>(dataReader.GetValue(0), re.GetValue(1));
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<object, object>)));
}
else if (PubConst.DicIS == type)
else if (UtilConstants.DicIS == type)
{
var kv = new KeyValuePair<int, string>(dataReader.GetValue(0).ObjToInt(), re.GetValue(1).ObjToString());
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<int, string>)));
}
else if (PubConst.Dicii == type)
else if (UtilConstants.Dicii == type)
{
var kv = new KeyValuePair<int, int>(dataReader.GetValue(0).ObjToInt(), re.GetValue(1).ObjToInt());
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<int, int>)));
}
else if (PubConst.DicSi == type)
else if (UtilConstants.DicSi == type)
{
var kv = new KeyValuePair<string, int>(dataReader.GetValue(0).ObjToString(), re.GetValue(1).ObjToInt());
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<string, int>)));
}
else if (PubConst.DicSo == type)
else if (UtilConstants.DicSo == type)
{
var kv = new KeyValuePair<string, object>(dataReader.GetValue(0).ObjToString(), re.GetValue(1));
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<string, object>)));
}
else if (PubConst.DicSS == type)
else if (UtilConstants.DicSS == type)
{
var kv = new KeyValuePair<string, string>(dataReader.GetValue(0).ObjToString(), dataReader.GetValue(1).ObjToString());
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<string, string>)));
@ -98,21 +98,21 @@ namespace SqlSugar
{
array[i] = Convert.ChangeType(re.GetValue(i), childType);
}
if (childType == PubConst.StringType)
if (childType == UtilConstants.StringType)
reval.Add((T)Convert.ChangeType(array.Select(it => it.ObjToString()).ToArray(), type));
else if (childType == PubConst.ObjType)
else if (childType == UtilConstants.ObjType)
reval.Add((T)Convert.ChangeType(array.Select(it => it == DBNull.Value ? null : (object)it).ToArray(), type));
else if (childType == PubConst.BoolType)
else if (childType == UtilConstants.BoolType)
reval.Add((T)Convert.ChangeType(array.Select(it => it.ObjToBool()).ToArray(), type));
else if (childType == PubConst.ByteType)
else if (childType == UtilConstants.ByteType)
reval.Add((T)Convert.ChangeType(array.Select(it => it == DBNull.Value ? 0 : (byte)it).ToArray(), type));
else if (childType == PubConst.DecType)
else if (childType == UtilConstants.DecType)
reval.Add((T)Convert.ChangeType(array.Select(it => it.ObjToDecimal()).ToArray(), type));
else if (childType == PubConst.GuidType)
else if (childType == UtilConstants.GuidType)
reval.Add((T)Convert.ChangeType(array.Select(it => it == DBNull.Value ? Guid.Empty : (Guid)it).ToArray(), type));
else if (childType == PubConst.DateType)
else if (childType == UtilConstants.DateType)
reval.Add((T)Convert.ChangeType(array.Select(it => it == DBNull.Value ? DateTime.MinValue : (DateTime)it).ToArray(), type));
else if (childType == PubConst.IntType)
else if (childType == UtilConstants.IntType)
reval.Add((T)Convert.ChangeType(array.Select(it => it.ObjToInt()).ToArray(), type));
else
Check.Exception(true, ErrorMessage.NotSupportedArray);
@ -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)));
}
}
}

View File

@ -17,7 +17,7 @@ namespace SqlSugar
#region Public methods
public virtual string GetDbTypeName(string csharpTypeName)
{
if (csharpTypeName == PubConst.ByteArrayType.Name)
if (csharpTypeName == UtilConstants.ByteArrayType.Name)
{
return "varbinary";
}
@ -143,7 +143,15 @@ namespace SqlSugar
{
dbTypeName = dbTypeName.ToLower();
var propertyTypes = MappingTypes.Where(it => it.Key == dbTypeName);
if (propertyTypes == null)
if (dbTypeName == "int32")
{
return "int";
}
else if (dbTypeName == "int64")
{
return "long";
}
else if (propertyTypes == null)
{
return "other";
}
@ -173,7 +181,7 @@ namespace SqlSugar
{
return GetKeyValueList<T>(type, dataReader);
}
else if (type.IsValueType() || type == PubConst.StringType)
else if (type.IsValueType() || type == UtilConstants.StringType)
{
return GetValueTypeList<T>(type, dataReader);
}

View File

@ -123,7 +123,7 @@ namespace SqlSugar
}
if (propertyInfo != null && propertyInfo.GetSetMethod() != null)
{
if (propertyInfo.PropertyType.IsClass() && propertyInfo.PropertyType != PubConst.ByteArrayType)
if (propertyInfo.PropertyType.IsClass() && propertyInfo.PropertyType != UtilConstants.ByteArrayType)
{
BindClass(generator, result, propertyInfo);
}
@ -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, @"\(.+\)"))
{
@ -186,15 +186,15 @@ namespace SqlSugar
{
method = isNullableType ? getConvertEnum_Null.MakeGenericMethod(bindPropertyType) : getEnum.MakeGenericMethod(bindPropertyType);
}
else if (bindPropertyType == PubConst.IntType)
else if (bindPropertyType == UtilConstants.IntType)
{
method = isNullableType ? getConvertInt32 : getInt32;
}
else if (bindPropertyType == PubConst.StringType)
else if (bindPropertyType == UtilConstants.StringType)
{
method = getString;
}
else if (bindPropertyType == PubConst.ByteArrayType)
else if (bindPropertyType == UtilConstants.ByteArrayType)
{
method = getValueMethod;
generator.Emit(OpCodes.Call, method);
@ -254,11 +254,13 @@ namespace SqlSugar
CheckType(bind.DoubleThrow, bindProperyTypeName, validPropertyName, propertyName);
if (bindProperyTypeName == "double")
method = isNullableType ? getConvertDouble : getDouble;
if(bindProperyTypeName=="single")
method = isNullableType ? getConvertFloat : getFloat;
break;
case CSharpDataType.Guid:
CheckType(bind.GuidThrow, bindProperyTypeName, validPropertyName, propertyName);
if (bindProperyTypeName == "guid")
method = isNullableType ? getConvertStringGuid : getStringGuid;
method = isNullableType ? getConvertGuid : getStringGuid;
break;
case CSharpDataType.@byte:
if (bindProperyTypeName == "byte")
@ -280,7 +282,7 @@ namespace SqlSugar
method = getValueMethod;
break;
}
if (method == null && bindPropertyType == PubConst.StringType)
if (method == null && bindPropertyType == UtilConstants.StringType)
{
method = getConvertString;
}
@ -299,7 +301,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

View File

@ -27,10 +27,6 @@ namespace SqlSugar
public static bool? GetConvertBoolean(this IDataRecord dr, int i)
{
if (dr.IsDBNull(i))
{
return null;
}
var reval = dr.GetBoolean(i);
return reval;
}
@ -57,11 +53,11 @@ namespace SqlSugar
public static DateTime? GetConvertDateTime(this IDataRecord dr, int i)
{
if (dr.IsDBNull(i))
{
return null;
}
var reval = dr.GetDateTime(i);
if (reval == DateTime.MinValue)
{
return null; ;
}
return reval;
}
@ -189,7 +185,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;
@ -205,27 +201,27 @@ namespace SqlSugar
private static T SqliteTypeConvert<T>(IDataReader dr, int i, Type type) where T : struct
{
if (type.IsIn(PubConst.IntType))
if (type.IsIn(UtilConstants.IntType))
{
return (T)((object)(dr.GetInt32(i)));
}
else if (type == PubConst.DateType)
else if (type == UtilConstants.DateType)
{
return (T)Convert.ChangeType(Convert.ToDateTime(dr.GetString(i)), type);
}
else if (type == PubConst.DecType)
else if (type == UtilConstants.DecType)
{
return (T)Convert.ChangeType(dr.GetDecimal(i), type);
}
else if (type == PubConst.DobType)
else if (type == UtilConstants.DobType)
{
return (T)Convert.ChangeType(dr.GetDouble(i), type);
}
else if (type == PubConst.BoolType)
else if (type == UtilConstants.BoolType)
{
return (T)Convert.ChangeType(dr.GetBoolean(i), type);
}
else if (type == PubConst.GuidType)
else if (type == UtilConstants.GuidType)
{
string guidString = dr.GetString(i);
string changeValue = guidString.IsNullOrEmpty() ? Guid.Empty.ToString() : guidString;

View File

@ -154,7 +154,7 @@ namespace SqlSugar
}
classText = classText.Replace(DbFirstTemplate.KeyClassName, className);
classText = classText.Replace(DbFirstTemplate.KeyNamespace, this.Namespace);
classText = classText.Replace(DbFirstTemplate.KeyUsing, IsAttribute ? (this.UsingTemplate + "using " + PubConst.AssemblyName + ";\r\n") : this.UsingTemplate);
classText = classText.Replace(DbFirstTemplate.KeyUsing, IsAttribute ? (this.UsingTemplate + "using " + UtilConstants.AssemblyName + ";\r\n") : this.UsingTemplate);
classText = classText.Replace(DbFirstTemplate.KeyClassDescription, this.ClassDescriptionTemplate.Replace(DbFirstTemplate.KeyClassDescription, tableInfo.Description + "\r\n"));
classText = classText.Replace(DbFirstTemplate.KeySugarTable, IsAttribute ? string.Format(DbFirstTemplate.ValueSugarTable, tableInfo.Name) : null);
if (columns.IsValuable())

View File

@ -238,10 +238,7 @@ namespace SqlSugar
{
string columnName = this.SqlBuilder.GetTranslationTableName(item.DbColumnName);
string dataType = item.DataType;
string dataSize = item.Length > 0 ? string.Format("({0})", item.Length) : null;
if (item.Length>4000|| item.Length==-1) {
dataSize = string.Format("({0})","max");
}
string dataSize = GetSize(item);
string nullType = item.IsNullable ? this.CreateTableNull : CreateTableNotNull;
string primaryKey = null;
string identity = item.IsIdentity ? this.CreateTableIdentity : null;
@ -256,7 +253,7 @@ namespace SqlSugar
string columnName = this.SqlBuilder.GetTranslationColumnName(columnInfo.DbColumnName);
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
string dataType = columnInfo.DataType;
string dataSize = columnInfo.Length > 0 ? string.Format("({0})", columnInfo.Length) : null;
string dataSize = GetSize(columnInfo);
string nullType = columnInfo.IsNullable ? this.CreateTableNull : CreateTableNotNull;
string primaryKey = null;
string identity = null;
@ -268,7 +265,7 @@ namespace SqlSugar
string columnName = this.SqlBuilder.GetTranslationTableName(columnInfo.DbColumnName);
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
string dataType = columnInfo.DataType;
string dataSize = columnInfo.Length > 0 ? string.Format("({0})", columnInfo.Length) : null;
string dataSize = GetSize(columnInfo);
string nullType = columnInfo.IsNullable ? this.CreateTableNull : CreateTableNotNull;
string primaryKey = null;
string identity = null;
@ -277,7 +274,25 @@ namespace SqlSugar
}
protected virtual string GetCacheKey(string cacheKey)
{
return this.Context.CurrentConnectionConfig.DbType + "." + this.Context.Ado.Connection.Database +"."+ cacheKey;
return this.Context.CurrentConnectionConfig.DbType + "." + this.Context.Ado.Connection.Database + "." + cacheKey;
}
protected virtual string GetSize(DbColumnInfo item)
{
string dataSize = null;
var isMax = item.Length > 4000 || item.Length == -1;
if (isMax)
{
dataSize = item.Length > 0 ? string.Format("({0})", "max") : null;
}
else if (item.Length > 0 && item.DecimalDigits == 0)
{
dataSize = item.Length > 0 ? string.Format("({0})", item.Length) : null;
}
else if (item.Length > 0 && item.DecimalDigits > 0)
{
dataSize = item.Length > 0 ? string.Format("({0},{1})", item.Length, item.DecimalDigits) : null;
}
return dataSize;
}
#endregion
}

View File

@ -84,14 +84,14 @@ namespace SqlSugar
var isFirst = deleteObjs.IndexOf(deleteObj) == 0;
if (isFirst)
{
orString.Append(DeleteBuilder.WhereInOrTemplate + PubConst.Space);
orString.Append(DeleteBuilder.WhereInOrTemplate + UtilConstants.Space);
}
int i = 0;
StringBuilder andString = new StringBuilder();
foreach (var primaryField in primaryFields)
{
if (i == 0)
andString.Append(DeleteBuilder.WhereInAndTemplate + PubConst.Space);
andString.Append(DeleteBuilder.WhereInAndTemplate + UtilConstants.Space);
var entityPropertyName = this.Context.EntityProvider.GetPropertyName<T>(primaryField);
var columnInfo = EntityInfo.Columns.Single(it => it.PropertyName == entityPropertyName);
var entityValue = columnInfo.PropertyInfo.GetValue(deleteObj, null);
@ -115,6 +115,7 @@ namespace SqlSugar
public IDeleteable<T> Where(T deleteObj)
{
Check.Exception(GetPrimaryKeys().IsNullOrEmpty(), "Where(entity) Primary key required");
Where(new List<T>() { deleteObj });
return this;
}

View File

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

View File

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

View File

@ -11,5 +11,6 @@ namespace SqlSugar
{
protected ILambdaExpressions _LambdaExpressions;
protected bool _RestoreMapping = true;
protected int _InQueryableIndex = 100;
}
}

View File

@ -131,7 +131,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 + PubConst.Space));
whereValue.Add(SqlBuilder.AppendWhereOrAnd(whereValue.Count == 0, whereString + UtilConstants.Space));
if (whereObj != null)
QueryBuilder.Parameters.AddRange(Context.Ado.GetParameters(whereObj));
return this;
@ -259,19 +259,12 @@ namespace SqlSugar
return In(expression, inValues.ToArray());
}
public virtual ISugarQueryable<T> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression) {
var sqlObj=childQueryExpression.ToSql();
if (sqlObj.Value.IsValuable()) {
this.QueryBuilder.Parameters.AddRange(sqlObj.Value);
}
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
var whereSql = string.Format(this.QueryBuilder.InTemplate, fieldName, sqlObj.Key);
this.QueryBuilder.WhereInfos.Add(SqlBuilder.AppendWhereOrAnd(this.QueryBuilder.WhereInfos.IsNullOrEmpty(),whereSql));
public virtual ISugarQueryable<T> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
{
var sqlObj = childQueryExpression.ToSql();
_InQueryable(expression, sqlObj);
return this;
}
public virtual ISugarQueryable<T> OrderBy(string orderFileds)
{
var orderByValue = QueryBuilder.OrderByValue;
@ -410,6 +403,14 @@ namespace SqlSugar
QueryBuilder.SelectValue = selectValue;
return this;
}
public virtual ISugarQueryable<T> MergeTable()
{
Check.Exception(this.QueryBuilder.SelectValue.IsNullOrEmpty(), "MergeTable need to use Select(it=>new{}) Method .");
Check.Exception(this.QueryBuilder.Skip > 0 || this.QueryBuilder.Take > 0, "MergeTable Queryable cannot Take Skip OrderBy PageToList ");
var sql = QueryBuilder.ToSqlString();
var tableName =this.SqlBuilder.GetPackTable (sql, "MergeTable");
return this.Context.Queryable<ExpandoObject>().AS(tableName).Select<T>("*");
}
public virtual int Count()
{
@ -576,7 +577,7 @@ namespace SqlSugar
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
OrderBy(lamResult.GetResultString() + PubConst.Space + type.ToString().ToUpper());
OrderBy(lamResult.GetResultString() + UtilConstants.Space + type.ToString().ToUpper());
return this;
}
protected ISugarQueryable<T> _GroupBy(Expression expression)
@ -675,6 +676,21 @@ namespace SqlSugar
SetContextModel(result, entityType);
return result;
}
protected void _InQueryable(Expression<Func<T, object>> expression, KeyValuePair<string, List<SugarParameter>> sqlObj)
{
string sql = sqlObj.Key;
if (sqlObj.Value.IsValuable())
{
this.SqlBuilder.RepairReplicationParameters(ref sql,sqlObj.Value.ToArray(),100);
this.QueryBuilder.Parameters.AddRange(sqlObj.Value);
}
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
var whereSql = string.Format(this.QueryBuilder.InTemplate, fieldName, sql);
this.QueryBuilder.WhereInfos.Add(SqlBuilder.AppendWhereOrAnd(this.QueryBuilder.WhereInfos.IsNullOrEmpty(), whereSql));
base._InQueryableIndex += 100;
}
protected List<string> GetPrimaryKeys()
{
@ -716,7 +732,7 @@ namespace SqlSugar
{
if (result.IsValuable())
{
if (entityType.GetTypeInfo().BaseType.IsValuable() && entityType.GetTypeInfo().BaseType == PubConst.ModelType)
if (entityType.GetTypeInfo().BaseType.IsValuable() && entityType.GetTypeInfo().BaseType == UtilConstants.ModelType)
{
foreach (var item in result)
{
@ -829,6 +845,31 @@ namespace SqlSugar
return _Avg<TResult>(expression);
}
#endregion
#region In
public new ISugarQueryable<T, T2> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
{
var sqlObj = childQueryExpression.ToSql();
_InQueryable(expression, sqlObj);
return this;
}
#endregion
}
#endregion
#region T3
@ -956,6 +997,31 @@ namespace SqlSugar
return _Avg<TResult>(expression);
}
#endregion
#region In
public new ISugarQueryable<T, T2, T3> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2, T3> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2, T3> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
{
var sqlObj = childQueryExpression.ToSql();
_InQueryable(expression, sqlObj);
return this;
}
#endregion
}
#endregion
#region T4
@ -1104,6 +1170,31 @@ namespace SqlSugar
return _Avg<TResult>(expression);
}
#endregion
#region In
public new ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
{
var sqlObj = childQueryExpression.ToSql();
_InQueryable(expression, sqlObj);
return this;
}
#endregion
}
#endregion
#region T5
@ -1278,6 +1369,31 @@ namespace SqlSugar
return _Avg<TResult>(expression);
}
#endregion
#region In
public new ISugarQueryable<T, T2, T3, T4, T5> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
{
var sqlObj = childQueryExpression.ToSql();
_InQueryable(expression, sqlObj);
return this;
}
#endregion
}
#endregion
#region T6
@ -1478,6 +1594,31 @@ namespace SqlSugar
return _Avg<TResult>(expression);
}
#endregion
#region In
public new ISugarQueryable<T, T2, T3, T4, T5, T6> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
{
var sqlObj = childQueryExpression.ToSql();
_InQueryable(expression, sqlObj);
return this;
}
#endregion
}
#endregion
#region T7
@ -1705,6 +1846,31 @@ namespace SqlSugar
return _Avg<TResult>(expression);
}
#endregion
#region In
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
{
var sqlObj = childQueryExpression.ToSql();
_InQueryable(expression, sqlObj);
return this;
}
#endregion
}
#endregion
#region T8
@ -1958,6 +2124,31 @@ namespace SqlSugar
return _Avg<TResult>(expression);
}
#endregion
#region In
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
{
var sqlObj = childQueryExpression.ToSql();
_InQueryable(expression, sqlObj);
return this;
}
#endregion
}
#endregion
#region T9
@ -2234,6 +2425,31 @@ namespace SqlSugar
return _Avg<TResult>(expression);
}
#endregion
#region In
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
{
var sqlObj = childQueryExpression.ToSql();
_InQueryable(expression, sqlObj);
return this;
}
#endregion
}
#endregion
#region T10
@ -2534,6 +2750,31 @@ namespace SqlSugar
return _Avg<TResult>(expression);
}
#endregion
#region In
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
{
var sqlObj = childQueryExpression.ToSql();
_InQueryable(expression, sqlObj);
return this;
}
#endregion
}
#endregion
#region T11
@ -2859,6 +3100,31 @@ namespace SqlSugar
return _Avg<TResult>(expression);
}
#endregion
#region In
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues)
{
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
{
var sqlObj = childQueryExpression.ToSql();
_InQueryable(expression, sqlObj);
return this;
}
#endregion
}
#endregion
#region T12
@ -3209,6 +3475,28 @@ namespace SqlSugar
return _Avg<TResult>(expression);
}
#endregion
#region In
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues) {
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues) {
var isSingle = QueryBuilder.IsSingle();
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
var fieldName = lamResult.GetResultString();
In(fieldName, inValues);
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression) {
var sqlObj = childQueryExpression.ToSql();
_InQueryable(expression, sqlObj);
return this;
}
#endregion
}
#endregion
}

View File

@ -23,7 +23,7 @@ namespace SqlSugar
{
get
{
_WhereInfos = PubMethod.IsNullReturnNew(_WhereInfos);
_WhereInfos = UtilMethods.IsNullReturnNew(_WhereInfos);
return _WhereInfos;
}
set { _WhereInfos = value; }
@ -83,10 +83,10 @@ namespace SqlSugar
get
{
var result = Builder.GetTranslationTableName(EntityInfo.EntityName);
result += PubConst.Space;
result += UtilConstants.Space;
if (this.TableWithString.IsValuable())
{
result += TableWithString + PubConst.Space;
result += TableWithString + UtilConstants.Space;
}
return result;
}
@ -102,7 +102,7 @@ namespace SqlSugar
{
var isFirst = i == 0;
whereString += isFirst ? "WHERE " : "AND ";
whereString += (item + PubConst.Space);
whereString += (item + UtilConstants.Space);
++i;
}
return whereString;

View File

@ -86,10 +86,10 @@ namespace SqlSugar
get
{
var result = Builder.GetTranslationTableName(EntityInfo.EntityName);
result += PubConst.Space;
result += UtilConstants.Space;
if (this.TableWithString.IsValuable())
{
result += TableWithString + PubConst.Space;
result += TableWithString + UtilConstants.Space;
}
return result;
}
@ -156,7 +156,7 @@ namespace SqlSugar
else
{
var type = value.GetType();
if (type == PubConst.DateType)
if (type == UtilConstants.DateType)
{
var date = value.ObjToDate();
if (date < Convert.ToDateTime("1900-1-1"))
@ -169,11 +169,11 @@ namespace SqlSugar
{
return Convert.ToInt64(value);
}
else if (type == PubConst.BoolType)
else if (type == UtilConstants.BoolType)
{
return value.ObjToBool() ? "1" : "0";
}
else if (type == PubConst.StringType || type == PubConst.ObjType)
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
{
return "N'" + value.ToString().ToSqlFilter() + "'";
}

View File

@ -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; }
@ -140,7 +140,7 @@ namespace SqlSugar
{
get
{
return "ORDER BY GETDATE() ";
return "ORDER BY "+this.Builder.SqlDateNow+" ";
}
}
public virtual string OrderByTemplate
@ -236,9 +236,9 @@ namespace SqlSugar
var rowNumberString = string.Format(",ROW_NUMBER() OVER({0}) AS RowIndex ", GetOrderByString);
string groupByValue = GetGroupByString + HavingInfos;
string orderByValue = (!isRowNumber && this.OrderByValue.IsValuable()) ? GetOrderByString : null;
if (this.IsCount) { orderByValue = null; }
if (this.IsCount) { orderByValue = null; this.OrderByValue = oldOrderBy; }
sql.AppendFormat(SqlTemplate, GetSelectValue, GetTableNameString, GetWhereValueString, groupByValue, orderByValue);
sql.Replace("{$:OrderByString:$}", isRowNumber ? (this.IsCount ? null : rowNumberString) : null);
sql.Replace(UtilConstants.OrderReplace, isRowNumber ? (this.IsCount ? null : rowNumberString) : null);
if (this.IsCount) { return sql.ToString(); }
var result = ToPageSql(sql.ToString(), this.Take, this.Skip);
if (ExternalPageIndex > 0)
@ -314,9 +314,9 @@ namespace SqlSugar
{
return string.Format(
this.JoinTemplate,
joinInfo.JoinType.ToString() + PubConst.Space,
Builder.GetTranslationTableName(joinInfo.TableName) + PubConst.Space,
joinInfo.ShortName + PubConst.Space + joinInfo.TableWithString,
joinInfo.JoinType.ToString() + UtilConstants.Space,
Builder.GetTranslationTableName(joinInfo.TableName) + UtilConstants.Space,
joinInfo.ShortName + UtilConstants.Space + joinInfo.TableWithString,
joinInfo.JoinWhere);
}
public virtual void Clear()
@ -392,7 +392,7 @@ namespace SqlSugar
if (this.WhereInfos == null) return null;
else
{
return string.Join(PubConst.Space, this.WhereInfos);
return string.Join(UtilConstants.Space, this.WhereInfos);
}
}
}
@ -403,7 +403,7 @@ namespace SqlSugar
if (this.JoinQueryInfos.IsNullOrEmpty()) return null;
else
{
return string.Join(PubConst.Space, this.JoinQueryInfos.Select(it => this.ToJoinString(it)));
return string.Join(UtilConstants.Space, this.JoinQueryInfos.Select(it => this.ToJoinString(it)));
}
}
}
@ -412,18 +412,18 @@ namespace SqlSugar
get
{
var result = Builder.GetTranslationTableName(EntityName);
result += PubConst.Space;
result += UtilConstants.Space;
if (this.TableWithString.IsValuable())
{
result += TableWithString + PubConst.Space;
result += TableWithString + UtilConstants.Space;
}
if (this.TableShortName.IsValuable())
{
result += (TableShortName + PubConst.Space);
result += (TableShortName + UtilConstants.Space);
}
if (!this.IsSingle())
{
result += GetJoinValueString + PubConst.Space;
result += GetJoinValueString + UtilConstants.Space;
}
if (this.EasyJoinInfos.IsValuable())
{
@ -459,7 +459,7 @@ namespace SqlSugar
if (this.GroupByValue == null) return null;
if (this.GroupByValue.Last() != ' ' )
{
return this.GroupByValue + PubConst.Space;
return this.GroupByValue + UtilConstants.Space;
}
return this.GroupByValue;
}

View File

@ -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; }
@ -69,7 +69,15 @@ namespace SqlSugar
public virtual string GetNoTranslationColumnName(string name)
{
if (!name.Contains(SqlTranslationLeft)) return name;
return name == null ? string.Empty : Regex.Match(name, @".*"+"\\"+SqlTranslationLeft+"(.*?)"+"\\"+SqlTranslationRight+"").Groups[1].Value;
return name == null ? string.Empty : Regex.Match(name, @".*" + "\\" + SqlTranslationLeft + "(.*?)" + "\\" + SqlTranslationRight + "").Groups[1].Value;
}
public virtual string GetPackTable(string sql, string shortName)
{
return UtilMethods.GetPackTable(sql,shortName);
}
public virtual void RepairReplicationParameters(ref string appendSql, SugarParameter[] parameters, int addIndex)
{
UtilMethods.RepairReplicationParameters(ref appendSql,parameters,addIndex);
}
#endregion

View File

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

View File

@ -92,10 +92,10 @@ namespace SqlSugar
get
{
var result = Builder.GetTranslationTableName(TableName);
result += PubConst.Space;
result += UtilConstants.Space;
if (this.TableWithString.IsValuable())
{
result += TableWithString + PubConst.Space;
result += TableWithString + UtilConstants.Space;
}
return result;
}
@ -250,7 +250,7 @@ namespace SqlSugar
else
{
var type = value.GetType();
if (type == PubConst.DateType)
if (type == UtilConstants.DateType)
{
var date = value.ObjToDate();
if (date < Convert.ToDateTime("1900-1-1"))
@ -263,11 +263,11 @@ namespace SqlSugar
{
return Convert.ToInt64(value);
}
else if (type == PubConst.BoolType)
else if (type == UtilConstants.BoolType)
{
return value.ObjToBool() ? "1" : "0";
}
else if (type == PubConst.StringType || type == PubConst.ObjType)
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
{
return "N'" + value.ToString().ToSqlFilter() + "'";
}

View File

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

View File

@ -19,5 +19,7 @@ namespace SqlSugar
public bool IsIdentity { get; set; }
public bool IsPrimarykey { get; set; }
public object Value { get; set; }
public int DecimalDigits { get; set; }
public int Scale { get; set; }
}
}

View File

@ -10,5 +10,6 @@ namespace SqlSugar
public const string MySql = "MySql";
public const string SqlServer = "SqlServer";
public const string Sqlite = "Sqlite";
public const string Oracle = "Oracle";
}
}

View File

@ -23,5 +23,6 @@ namespace SqlSugar
public string DbTableName { get; set; }
public bool IsIgnore { get; set; }
public string DataType { get; set; }
public int DecimalDigits { get; set; }
}
}

View File

@ -86,6 +86,12 @@ namespace SqlSugar
get { return _ColumnDataType; }
set { _ColumnDataType = value; }
}
private int _DecimalDigits;
public int DecimalDigits {
get { return _DecimalDigits; }
set { _DecimalDigits = value; }
}
}
}

View File

@ -11,5 +11,4 @@ namespace SqlSugar
Left = 1,
Right = 2
}
}

View File

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
internal static partial class ErrorMessage
{
internal static string OperatorError
{
get
{
return ErrorMessage.GetThrowMessage("Lambda parsing error: {0} does not support the operator to find!","拉姆达解析出错:不支持{0}此种运算符查找!");
}
}
internal static string ExpFileldError
{
get
{
return ErrorMessage.GetThrowMessage("Expression format error, correct format: it=>it.fieldName","表达示格式错误,正确格式: it=>it.fieldName");
}
}
internal static string MethodError
{
get
{
return ErrorMessage.GetThrowMessage("Expression parsing does not support the current function {0}. There are many functions available in the SqlFunc class, for example, it=>SqlFunc.HasValue(it.Id)", "拉姆达解析不支持当前函数{0}SqlFunc这个类里面有大量函数可用,也许有你想要的,例如: it=>SqlFunc.HasValue(it.Id)");
}
}
}
}

View File

@ -18,13 +18,5 @@ namespace SqlSugar
public const string Const = "Const";
public readonly static Type MemberExpressionType = typeof(MemberExpression);
public readonly static Type ConstantExpressionType = typeof(ConstantExpression);
public readonly static Type StringType = typeof(string);
internal static string GetThrowMessage(string enMessage, string cnMessage, params string[] args)
{
List<string> formatArgs = new List<string>() { enMessage, cnMessage };
formatArgs.AddRange(args);
return string.Format("\r\n English Message : {0}\r\n Chinese Message : {1}", formatArgs.ToArray());
}
}
}

View File

@ -1,33 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
internal class ExpressionErrorMessage
{
internal static string OperatorError
{
get
{
return ExpressionConst.GetThrowMessage("Lambda parsing error: {0} does not support the operator to find!","拉姆达解析出错:不支持{0}此种运算符查找!");
}
}
internal static string ExpFileldError
{
get
{
return ExpressionConst.GetThrowMessage("Expression format error, correct format: it=>it.fieldName","表达示格式错误,正确格式: it=>it.fieldName");
}
}
internal static string MethodError
{
get
{
return ExpressionConst.GetThrowMessage("Expression parsing does not support the current function {0}. There are many functions available in the SqlFunc class, for example, it=>SqlFunc.HasValue(it.Id)", "拉姆达解析不支持当前函数{0}SqlFunc这个类里面有大量函数可用,也许有你想要的,例如: it=>SqlFunc.HasValue(it.Id)");
}
}
}
}

View File

@ -42,7 +42,7 @@ namespace SqlSugar
case ExpressionType.MultiplyChecked:
return "*";
default:
Check.ThrowNotSupportedException(string.Format(ExpressionErrorMessage.OperatorError, expressiontype.ToString()));
Check.ThrowNotSupportedException(string.Format(ErrorMessage.OperatorError, expressiontype.ToString()));
return null;
}
}
@ -147,7 +147,7 @@ namespace SqlSugar
FieldInfo field = (FieldInfo)memberExpr.Member;
Check.Exception(field.IsPrivate, string.Format(" Field \"{0}\" can't be private ", field.Name));
reval = field.GetValue(memberExpr.Member);
if (reval != null && reval.GetType().IsClass() && reval.GetType() != ExpressionConst.StringType)
if (reval != null && reval.GetType().IsClass() && reval.GetType() != UtilConstants.StringType)
{
var fieldName = memberExpr.Member.Name;
var proInfo = reval.GetType().GetProperty(fieldName);
@ -190,7 +190,7 @@ namespace SqlSugar
object reval = null;
PropertyInfo pro = (PropertyInfo)memberExpr.Member;
reval = pro.GetValue(memberExpr.Member, null);
if (reval != null && reval.GetType().IsClass() && reval.GetType() != ExpressionConst.StringType)
if (reval != null && reval.GetType().IsClass() && reval.GetType() != UtilConstants.StringType)
{
var fieldName = memberExpr.Member.Name;
var proInfo = reval.GetType().GetProperty(fieldName);
@ -214,7 +214,7 @@ namespace SqlSugar
public static object DynamicInvoke(Expression expression,MemberExpression memberExpression=null)
{
object value = Expression.Lambda(expression).Compile().DynamicInvoke();
if (value != null && value.GetType().IsClass() && value.GetType() != ExpressionConst.StringType&& memberExpression!=null)
if (value != null && value.GetType().IsClass() && value.GetType() != UtilConstants.StringType&& memberExpression!=null)
{
value = Expression.Lambda(memberExpression).Compile().DynamicInvoke();
}
@ -233,7 +233,7 @@ namespace SqlSugar
public static bool IsEntity(Type type)
{
return type.IsClass() && type != ExpressionConst.StringType;
return type.IsClass() && type != UtilConstants.StringType;
}
public static bool IsValueType(Type type)

View File

@ -27,47 +27,47 @@ namespace SqlSugar
private void SettingDataType(Type type)
{
if (type == PubConst.ByteArrayType)
if (type == UtilConstants.ByteArrayType)
{
this.DbType = System.Data.DbType.Binary;
}
else if (type == PubConst.GuidType)
else if (type == UtilConstants.GuidType)
{
this.DbType = System.Data.DbType.Guid;
}
else if (type == PubConst.IntType)
else if (type == UtilConstants.IntType)
{
this.DbType = System.Data.DbType.Int32;
}
else if (type == PubConst.ShortType)
else if (type == UtilConstants.ShortType)
{
this.DbType = System.Data.DbType.Int16;
}
else if (type == PubConst.LongType)
else if (type == UtilConstants.LongType)
{
this.DbType = System.Data.DbType.Int64;
}
else if (type == PubConst.DateType)
else if (type == UtilConstants.DateType)
{
this.DbType = System.Data.DbType.DateTime;
}
else if (type == PubConst.DobType)
else if (type == UtilConstants.DobType)
{
this.DbType = System.Data.DbType.Double;
}
else if (type == PubConst.DecType)
else if (type == UtilConstants.DecType)
{
this.DbType = System.Data.DbType.Decimal;
}
else if (type == PubConst.ByteType)
else if (type == UtilConstants.ByteType)
{
this.DbType = System.Data.DbType.Byte;
}
else if (type == PubConst.FloatType)
else if (type == UtilConstants.FloatType)
{
this.DbType = System.Data.DbType.Single;
}
else if (type == PubConst.BoolType)
else if (type == UtilConstants.BoolType)
{
this.DbType = System.Data.DbType.Boolean;
}
@ -109,7 +109,7 @@ namespace SqlSugar
{
if (_Size == 0 && Value != null)
{
var isByteArray = Value.GetType() == PubConst.ByteArrayType;
var isByteArray = Value.GetType() == UtilConstants.ByteArrayType;
if (isByteArray)
_Size = -1;
else

View File

@ -96,6 +96,8 @@ namespace SqlSugar
return "@";
}
}
public virtual string SqlTranslationLeft { get { return "["; } }
public virtual string SqlTranslationRight { get { return "]"; } }
#endregion
#region public functions
@ -103,34 +105,30 @@ namespace SqlSugar
{
Check.ArgumentNullException(entityName, string.Format(ErrorMessage.ObjNotExist, "Table Name"));
if (IsTranslationText(entityName)) return entityName;
if (isMapping && this.MappingTables.IsValuable())
isMapping = isMapping && this.MappingTables.IsValuable();
var isComplex = entityName.Contains(".");
if (isMapping && isComplex)
{
if (entityName.Contains("."))
var columnInfo = entityName.Split('.');
var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(columnInfo.Last(), StringComparison.CurrentCultureIgnoreCase));
if (mappingInfo != null)
{
var columnInfo = entityName.Split('.');
var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(columnInfo.Last(), StringComparison.CurrentCultureIgnoreCase));
if (mappingInfo != null)
{
columnInfo[columnInfo.Length - 1] = mappingInfo.EntityName;
}
return string.Join(".", columnInfo.Select(it => GetTranslationText(it)));
}
else
{
var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(entityName, StringComparison.CurrentCultureIgnoreCase));
return "[" + (mappingInfo == null ? entityName : mappingInfo.EntityName) + "]";
columnInfo[columnInfo.Length - 1] = mappingInfo.EntityName;
}
return string.Join(".", columnInfo.Select(it => GetTranslationText(it)));
}
else if (isMapping)
{
var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(entityName, StringComparison.CurrentCultureIgnoreCase));
return SqlTranslationLeft + (mappingInfo == null ? entityName : mappingInfo.EntityName) + SqlTranslationRight;
}
else if (isComplex)
{
return string.Join(".", entityName.Split('.').Select(it => GetTranslationText(it)));
}
else
{
if (entityName.Contains("."))
{
return string.Join(".", entityName.Split('.').Select(it => GetTranslationText(it)));
}
else
{
return GetTranslationText(entityName);
}
return GetTranslationText(entityName);
}
}
public virtual string GetTranslationColumnName(string columnName)
@ -164,11 +162,11 @@ namespace SqlSugar
}
public virtual bool IsTranslationText(string name)
{
return name.Contains("[") && name.Contains("]");
return name.Contains(SqlTranslationLeft) && name.Contains(SqlTranslationRight);
}
public virtual string GetTranslationText(string name)
{
return "[" + name + "]";
return SqlTranslationLeft + name + SqlTranslationRight;
}
public virtual void Resolve(Expression expression, ResolveExpressType resolveType)
{
@ -179,7 +177,7 @@ namespace SqlSugar
}
public virtual string GetAsString(string asName, string fieldValue)
{
if (fieldValue.Contains(".*")|| fieldValue=="*") return fieldValue;
if (fieldValue.Contains(".*") || fieldValue == "*") return fieldValue;
return string.Format(" {0} {1} {2} ", GetTranslationColumnName(fieldValue), "AS", GetTranslationColumnName(asName));
}

View File

@ -33,7 +33,7 @@ namespace SqlSugar
{
var parentIsBinary = parameter.BaseParameter.CurrentExpression is BinaryExpression;
var parentIsRoot = parameter.BaseParameter.CurrentExpression is LambdaExpression;
var isBool = value != null && value.GetType() == PubConst.BoolType;
var isBool = value != null && value.GetType() == UtilConstants.BoolType;
if (parentIsRoot && isBool)
{
this.Context.Result.Append(value.ObjToBool() ? this.Context.DbMehtods.True() : this.Context.DbMehtods.False());

View File

@ -15,10 +15,10 @@ namespace SqlSugar
var isSetTempData = baseParameter.CommonTempData.IsValuable() && baseParameter.CommonTempData.Equals(CommonTempDataType.Result);
var expression = base.Expression as MemberExpression;
var isValue = expression.Member.Name == "Value" && expression.Member.DeclaringType.Name == "Nullable`1";
var isBool = expression.Type == PubConst.BoolType;
var isBool = expression.Type == UtilConstants.BoolType;
var isValueBool = isValue && isBool && parameter.BaseExpression == null;
var isLength = expression.Member.Name == "Length" && (expression.Expression as MemberExpression).Type == PubConst.StringType;
var isDateValue = expression.Member.Name.IsIn(Enum.GetNames(typeof(DateType))) && (expression.Expression as MemberExpression).Type == PubConst.DateType;
var isLength = expression.Member.Name == "Length" && (expression.Expression as MemberExpression).Type == UtilConstants.StringType;
var isDateValue = expression.Member.Name.IsIn(Enum.GetNames(typeof(DateType))) && (expression.Expression as MemberExpression).Type == UtilConstants.DateType;
var isLogicOperator = ExpressionTool.IsLogicOperator(baseParameter.OperatorValue) || baseParameter.OperatorValue.IsNullOrEmpty();
var isHasValue = isLogicOperator && expression.Member.Name == "HasValue" && expression.Expression != null && expression.NodeType == ExpressionType.MemberAccess;
if (isLength)
@ -144,7 +144,7 @@ namespace SqlSugar
{
fieldName = GetName(parameter, expression, isLeft, isSingle);
}
if (expression.Type == PubConst.BoolType && baseParameter.OperatorValue.IsNullOrEmpty())
if (expression.Type == UtilConstants.BoolType && baseParameter.OperatorValue.IsNullOrEmpty())
{
fieldName = "( " + fieldName + "=1 )";
}

View File

@ -161,10 +161,10 @@ namespace SqlSugar
var isBinaryExpression = item is BinaryExpression || item is MethodCallExpression;
var isConst = item is ConstantExpression;
var isIIF= name == "IIF";
var isIFFBoolMember = isIIF && (item is MemberExpression) && (item as MemberExpression).Type == PubConst.BoolType;
var isIFFUnary = isIIF && (item is UnaryExpression) && (item as UnaryExpression).Operand.Type == PubConst.BoolType;
var isIFFBoolBinary = isIIF && (item is BinaryExpression) && (item as BinaryExpression).Type == PubConst.BoolType;
var isIFFBoolMethod = isIIF && (item is MethodCallExpression) && (item as MethodCallExpression).Type == PubConst.BoolType;
var isIFFBoolMember = isIIF && (item is MemberExpression) && (item as MemberExpression).Type == UtilConstants.BoolType;
var isIFFUnary = isIIF && (item is UnaryExpression) && (item as UnaryExpression).Operand.Type == UtilConstants.BoolType;
var isIFFBoolBinary = isIIF && (item is BinaryExpression) && (item as BinaryExpression).Type == UtilConstants.BoolType;
var isIFFBoolMethod = isIIF && (item is MethodCallExpression) && (item as MethodCallExpression).Type == UtilConstants.BoolType;
var isFirst = item == args.First();
if (isFirst && isIIF && isConst)
{
@ -427,7 +427,7 @@ namespace SqlSugar
private void CheckMethod(MethodCallExpression expression)
{
Check.Exception(expression.Method.ReflectedType().FullName != ExpressionConst.SqlFuncFullName, string.Format(ExpressionErrorMessage.MethodError, expression.Method.Name));
Check.Exception(expression.Method.ReflectedType().FullName != ExpressionConst.SqlFuncFullName, string.Format(ErrorMessage.MethodError, expression.Method.Name));
}
}
}

View File

@ -22,11 +22,11 @@ namespace SqlSugar
Check.ThrowNotSupportedException(expression.ToString());
break;
case ResolveExpressType.SelectSingle:
Check.Exception(expression.Type == PubConst.DateType, "ThrowNotSupportedException {0} ",expression.ToString());
Check.Exception(expression.Type == UtilConstants.DateType, "ThrowNotSupportedException {0} ",expression.ToString());
Select(expression, parameter, true);
break;
case ResolveExpressType.SelectMultiple:
Check.Exception(expression.Type == PubConst.DateType, "ThrowNotSupportedException {0} ", expression.ToString());
Check.Exception(expression.Type == UtilConstants.DateType, "ThrowNotSupportedException {0} ", expression.ToString());
Select(expression, parameter, false);
break;
case ResolveExpressType.FieldSingle:

View File

@ -92,7 +92,7 @@ namespace SqlSugar
parameter.CommonTempData = null;
}
}
else if (memberExpression.Type == PubConst.BoolType && isLogicOperator)
else if (memberExpression.Type == UtilConstants.BoolType && isLogicOperator)
{
Append(parameter, nodeType);
}

View File

@ -8,7 +8,7 @@ namespace SqlSugar
{
public class InstanceFactory
{
static Assembly assembly = ReflectionCore.Load(PubConst.AssemblyName);
static Assembly assembly = Assembly.Load(UtilConstants.AssemblyName);
static Dictionary<string, Type> typeCache = new Dictionary<string, Type>();
#region Queryable
@ -202,7 +202,7 @@ namespace SqlSugar
private static string GetClassName(string type, string name)
{
return PubConst.AssemblyName + "." + type + name;
return UtilConstants.AssemblyName + "." + type + name;
}
#region CreateInstance

View File

@ -26,7 +26,10 @@ namespace SqlSugar
{
try
{
dic.Add(reader.GetName(i), reader.GetValue(i));
var addItem = reader.GetValue(i);
if (addItem == DBNull.Value)
addItem = null;
dic.Add(reader.GetName(i), addItem);
}
catch
{
@ -66,7 +69,10 @@ namespace SqlSugar
{
try
{
result.Add(reader.GetName(i), reader.GetValue(i));
var addItem = reader.GetValue(i);
if (addItem == DBNull.Value)
addItem = null;
result.Add(reader.GetName(i), addItem);
}
catch
{
@ -108,29 +114,30 @@ namespace SqlSugar
var addValue = readerValues[name];
if (addValue == DBNull.Value)
{
if (item.PropertyType.IsIn(PubConst.IntType, PubConst.DecType, PubConst.DobType, PubConst.ByteType))
if (item.PropertyType.IsIn(UtilConstants.IntType, UtilConstants.DecType, UtilConstants.DobType, UtilConstants.ByteType))
{
addValue = 0;
}
else if (item.PropertyType == PubConst.GuidType)
else if (item.PropertyType == UtilConstants.GuidType)
{
addValue = Guid.Empty;
}
else if (item.PropertyType == PubConst.DateType)
else if (item.PropertyType == UtilConstants.DateType)
{
addValue = DateTime.MinValue;
}
else if (item.PropertyType == PubConst.StringType)
else if (item.PropertyType == UtilConstants.StringType)
{
addValue = null;
}
else {
else
{
addValue = null;
}
}
else
{
if (item.PropertyType == PubConst.IntType)
if (item.PropertyType == UtilConstants.IntType)
{
addValue = Convert.ToInt32(addValue);
}
@ -165,10 +172,10 @@ namespace SqlSugar
var key = typeName + "." + name;
if (readerValues.ContainsKey(key))
{
var addValue = readerValues[key];
if (addValue == DBNull.Value)
addValue = null;
result.Add(name,addValue );
var addItem = readerValues[key];
if (addItem == DBNull.Value)
addItem = null;
result.Add(name, addItem);
}
}
}
@ -194,10 +201,6 @@ namespace SqlSugar
/// <returns></returns>
public T DeserializeObject<T>(string value)
{
if (value.IsValuable())
{
value = value.Replace(":{}", ":null");
}
var jSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
return JsonConvert.DeserializeObject<T>(value,jSetting);
}
@ -231,10 +234,10 @@ namespace SqlSugar
childRow = new Dictionary<string, object>();
foreach (DataColumn col in table.Columns)
{
var addValue = row[col];
if (addValue == DBNull.Value)
addValue = null;
childRow.Add(col.ColumnName, addValue);
var addItem = row[col];
if (addItem == DBNull.Value)
addItem = null;
childRow.Add(col.ColumnName, addItem);
}
deserializeObject.Add(childRow);
}

View File

@ -277,7 +277,7 @@ namespace SqlSugar
var index = 1;
foreach (var item in entityTypeArray)
{
result.Add(PubConst.Space +lambdaParameters[index].Name, item.Name);
result.Add(UtilConstants.Space +lambdaParameters[index].Name, item.Name);
++index;
}
return result;

View File

@ -62,7 +62,7 @@ namespace SqlSugar
ISugarQueryable<TResult> Select<TResult>(Expression<Func<T, TResult>> expression);
ISugarQueryable<TResult> Select<TResult>(string select);
ISugarQueryable<T> Select(string select);
ISugarQueryable<T> MergeTable();
int Count();
TResult Max<TResult>(string maxField);
@ -125,6 +125,12 @@ namespace SqlSugar
TResult Sum<TResult>(Expression<Func<T,T2, TResult>> expression);
TResult Avg<TResult>(Expression<Func<T,T2, TResult>> expression);
#endregion
#region In
new ISugarQueryable<T,T2> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues);
new ISugarQueryable<T,T2> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues);
new ISugarQueryable<T,T2> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression);
#endregion
}
public partial interface ISugarQueryable<T, T2, T3> : ISugarQueryable<T>
{
@ -164,6 +170,12 @@ namespace SqlSugar
TResult Sum<TResult>(Expression<Func<T, T2,T3, TResult>> expression);
TResult Avg<TResult>(Expression<Func<T, T2,T3, TResult>> expression);
#endregion
#region In
new ISugarQueryable<T, T2,T3> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues);
new ISugarQueryable<T, T2,T3> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues);
new ISugarQueryable<T, T2,T3> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression);
#endregion
}
public partial interface ISugarQueryable<T, T2, T3, T4> : ISugarQueryable<T>
{
@ -208,6 +220,12 @@ namespace SqlSugar
TResult Sum<TResult>(Expression<Func<T, T2, T3,T4,TResult>> expression);
TResult Avg<TResult>(Expression<Func<T, T2, T3,T4,TResult>> expression);
#endregion
#region In
new ISugarQueryable<T, T2, T3,T4> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues);
new ISugarQueryable<T, T2, T3,T4> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues);
new ISugarQueryable<T, T2, T3,T4> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression);
#endregion
}
public partial interface ISugarQueryable<T, T2, T3, T4, T5> : ISugarQueryable<T>
{
@ -258,6 +276,12 @@ namespace SqlSugar
TResult Sum<TResult>(Expression<Func<T, T2, T3, T4,T5,TResult>> expression);
TResult Avg<TResult>(Expression<Func<T, T2, T3, T4,T5,TResult>> expression);
#endregion
#region In
new ISugarQueryable<T, T2, T3, T4,T5> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues);
new ISugarQueryable<T, T2, T3, T4,T5> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues);
new ISugarQueryable<T, T2, T3, T4,T5> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression);
#endregion
}
public partial interface ISugarQueryable<T, T2, T3, T4, T5, T6> : ISugarQueryable<T>
{
@ -312,6 +336,12 @@ namespace SqlSugar
TResult Sum<TResult>(Expression<Func<T, T2, T3, T4, T5,T6,TResult>> expression);
TResult Avg<TResult>(Expression<Func<T, T2, T3, T4, T5,T6,TResult>> expression);
#endregion
#region In
new ISugarQueryable<T, T2, T3, T4,T5,T6> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues);
new ISugarQueryable<T, T2, T3, T4,T5,T6> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues);
new ISugarQueryable<T, T2, T3, T4,T5,T6> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression);
#endregion
}
public partial interface ISugarQueryable<T, T2, T3, T4, T5, T6, T7> : ISugarQueryable<T>
{
@ -371,6 +401,12 @@ namespace SqlSugar
TResult Sum<TResult>(Expression<Func<T, T2, T3, T4, T5, T6,T7,TResult>> expression);
TResult Avg<TResult>(Expression<Func<T, T2, T3, T4, T5, T6,T7,TResult>> expression);
#endregion
#region In
new ISugarQueryable<T, T2, T3, T4, T5, T6,T7> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues);
new ISugarQueryable<T, T2, T3, T4, T5, T6,T7> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues);
new ISugarQueryable<T, T2, T3, T4, T5, T6,T7> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression);
#endregion
}
public partial interface ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> : ISugarQueryable<T>
{
@ -435,6 +471,12 @@ namespace SqlSugar
TResult Sum<TResult>(Expression<Func<T, T2, T3, T4, T5, T6, T7,T8, TResult>> expression);
TResult Avg<TResult>(Expression<Func<T, T2, T3, T4, T5, T6, T7,T8, TResult>> expression);
#endregion
#region In
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7,T8> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues);
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7,T8> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues);
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7,T8> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression);
#endregion
}
#region 9-12
@ -506,6 +548,12 @@ namespace SqlSugar
TResult Sum<TResult>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8,T9, TResult>> expression);
TResult Avg<TResult>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8,T9, TResult>> expression);
#endregion
#region In
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8,T9> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues);
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8,T9> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues);
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8,T9> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression);
#endregion
}
public partial interface ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8,T9,T10> : ISugarQueryable<T>
{
@ -580,6 +628,12 @@ namespace SqlSugar
TResult Sum<TResult>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9,T10, TResult>> expression);
TResult Avg<TResult>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9,T10, TResult>> expression);
#endregion
#region In
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9,T10> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues);
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9,T10> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues);
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9,T10> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression);
#endregion
}
public partial interface ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8,T9,T10,T11> : ISugarQueryable<T>
{
@ -659,6 +713,12 @@ namespace SqlSugar
TResult Sum<TResult>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10,T11, TResult>> expression);
TResult Avg<TResult>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10,T11, TResult>> expression);
#endregion
#region In
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10,T11> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues);
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10,T11> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues);
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10,T11> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression);
#endregion
}
public partial interface ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8,T9,T10,T11,T12> : ISugarQueryable<T>
{
@ -743,6 +803,12 @@ namespace SqlSugar
TResult Sum<TResult>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,T12, TResult>> expression);
TResult Avg<TResult>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,T12, TResult>> expression);
#endregion
#region In
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,T12> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues);
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,T12> In<FieldType>(Expression<Func<T, object>> expression, List<FieldType> inValues);
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,T12> In<FieldType>(Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression);
#endregion
}
#endregion
}

View File

@ -26,6 +26,7 @@ namespace SqlSugar
string GetTranslationColumnName(string entityName, string propertyName);
string GetTranslationColumnName(string propertyName);
string GetNoTranslationColumnName(string name);
string GetPackTable(string sql,string shortName);
void RepairReplicationParameters(ref string appendSql, SugarParameter[] parameters, int addIndex);
}
}

View File

@ -4,4 +4,7 @@
{
void Fill(DataSet ds);
}
}
namespace System.Data.Sqlite {
}

View File

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

View File

@ -8,7 +8,7 @@ namespace SqlSugar
{
public override string GetDbTypeName(string csharpTypeName)
{
if (csharpTypeName == PubConst.ByteArrayType.Name)
if (csharpTypeName == UtilConstants.ByteArrayType.Name)
{
return "blob";
}

View File

@ -9,48 +9,8 @@ namespace SqlSugar
{
base.DbMehtods = new MySqlMethod();
}
public override string GetTranslationTableName(string entityName, bool isMapping = true)
{
Check.ArgumentNullException(entityName, string.Format(ErrorMessage.ObjNotExist, "Table Name"));
if (IsTranslationText(entityName)) return entityName;
if (isMapping && this.MappingTables.IsValuable())
{
if (entityName.Contains("."))
{
var columnInfo = entityName.Split('.');
var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(columnInfo.Last(), StringComparison.CurrentCultureIgnoreCase));
if (mappingInfo != null)
{
columnInfo[columnInfo.Length - 1] = mappingInfo.EntityName;
}
return string.Join(".", columnInfo.Select(it => GetTranslationText(it)));
}
else
{
var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(entityName, StringComparison.CurrentCultureIgnoreCase));
return "`" + (mappingInfo == null ? entityName : mappingInfo.EntityName) + "`";
}
}
else
{
if (entityName.Contains("."))
{
return string.Join(".", entityName.Split('.').Select(it => GetTranslationText(it)));
}
else
{
return GetTranslationText(entityName);
}
}
}
public override bool IsTranslationText(string name)
{
return name.Contains("`") && name.Contains("`");
}
public override string GetTranslationText(string name)
{
return "`" + name + "`";
}
public override string SqlTranslationLeft { get { return "`"; } }
public override string SqlTranslationRight { get { return "`"; } }
}
public class MySqlMethod : DefaultDbMethod, IDbMethods
{

View File

@ -12,7 +12,7 @@ namespace SqlSugar
{
get
{
return "SELECT {0}{{$:OrderByString:$}} FROM {1}{2}{3}{4}";
return "SELECT {0}{"+UtilConstants.OrderReplace+"} FROM {1}{2}{3}{4}";
}
}
}

View File

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

View File

@ -8,7 +8,7 @@ namespace SqlSugar
{
public override string GetDbTypeName(string csharpTypeName)
{
if (csharpTypeName == PubConst.ByteArrayType.Name)
if (csharpTypeName == UtilConstants.ByteArrayType.Name)
{
return "blob";
}

View File

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.Sqlite;
using System.Linq;
using System.Text;
@ -22,14 +23,14 @@ namespace SqlSugar
{
get
{
return @"select Name from sqlite_master where type='table' and name<>'sqlite_sequence' order by name;";
return @"select Name from Sqlite_master where type='table' and name<>'Sqlite_sequence' order by name;";
}
}
protected override string GetViewInfoListSql
{
get
{
return @"select Name from sqlite_master where type='view' order by name;";
return @"select Name from Sqlite_master where type='view' order by name;";
}
}
#endregion
@ -127,7 +128,7 @@ namespace SqlSugar
{
get
{
return "select Name from sqlite_master limit 0,1";
return "select Name from Sqlite_master limit 0,1";
}
}
#endregion
@ -175,32 +176,27 @@ namespace SqlSugar
}, (cm, key) =>
{
string sql = "PRAGMA table_info(" + tableName + ")";
string sql = "select * from " + tableName + " limit 0,1";
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
this.Context.Ado.IsEnableLogEvent = false;
using (DbDataReader dataReader = (SqliteDataReader)this.Context.Ado.GetDataReader(sql))
using (DbDataReader reader = (SqliteDataReader)this.Context.Ado.GetDataReader(sql))
{
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog;
List<DbColumnInfo> result = new List<DbColumnInfo>();
while (dataReader.Read())
var schemaTable = reader.GetSchemaTable();
foreach (DataRow row in schemaTable.Rows)
{
var type = dataReader.GetValue(2).ObjToString();
var length = 0;
if (type.Contains("("))
{
type = type.Split('(').First();
length = type.Split('(').Last().TrimEnd(')').ObjToInt();
}
DbColumnInfo column = new DbColumnInfo()
{
TableName = tableName,
DataType = type,
IsNullable = !dataReader.GetBoolean(3),
IsIdentity = dataReader.GetBoolean(3) && dataReader.GetBoolean(5).ObjToBool() && (type.IsIn("integer", "int", "int32", "int64", "long")),
DataType = row["DataTypeName"].ToString().Trim(),
IsNullable = (bool)row["AllowDBNull"],
IsIdentity = (bool)row["IsAutoIncrement"],
ColumnDescription = null,
DbColumnName = dataReader.GetString(1),
DefaultValue = dataReader.GetValue(4).ObjToString(),
IsPrimarykey = dataReader.GetBoolean(5).ObjToBool(),
Length = length
DbColumnName = row["ColumnName"].ToString(),
DefaultValue = row["defaultValue"].ToString(),
IsPrimarykey = (bool)row["IsKey"],
Length = Convert.ToInt32(row["ColumnSize"])
};
result.Add(column);
}

View File

@ -9,48 +9,8 @@ namespace SqlSugar
{
base.DbMehtods = new SqliteMethod();
}
public override string GetTranslationTableName(string entityName, bool isMapping = true)
{
Check.ArgumentNullException(entityName, string.Format(ErrorMessage.ObjNotExist, "Table Name"));
if (IsTranslationText(entityName)) return entityName;
if (isMapping && this.MappingTables.IsValuable())
{
if (entityName.Contains("."))
{
var columnInfo = entityName.Split('.');
var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(columnInfo.Last(), StringComparison.CurrentCultureIgnoreCase));
if (mappingInfo != null)
{
columnInfo[columnInfo.Length - 1] = mappingInfo.EntityName;
}
return string.Join(".", columnInfo.Select(it => GetTranslationText(it)));
}
else
{
var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(entityName, StringComparison.CurrentCultureIgnoreCase));
return "`" + (mappingInfo == null ? entityName : mappingInfo.EntityName) + "`";
}
}
else
{
if (entityName.Contains("."))
{
return string.Join(".", entityName.Split('.').Select(it => GetTranslationText(it)));
}
else
{
return GetTranslationText(entityName);
}
}
}
public override bool IsTranslationText(string name)
{
return name.Contains("`") && name.Contains("`");
}
public override string GetTranslationText(string name)
{
return "`" + name + "`";
}
public override string SqlTranslationLeft { get { return "`"; } }
public override string SqlTranslationRight { get { return "`"; } }
}
public class SqliteMethod : DefaultDbMethod, IDbMethods
{

View File

@ -43,7 +43,7 @@ namespace SqlSugar
else
{
var type = value.GetType();
if (type == PubConst.DateType)
if (type == UtilConstants.DateType)
{
var date = value.ObjToDate();
if (date < Convert.ToDateTime("1900-1-1"))
@ -56,11 +56,11 @@ namespace SqlSugar
{
return Convert.ToInt64(value);
}
else if (type == PubConst.BoolType)
else if (type == UtilConstants.BoolType)
{
return value.ObjToBool() ? "1" : "0";
}
else if (type == PubConst.StringType || type == PubConst.ObjType)
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
{
return "'" + value.ToString().ToSqlFilter() + "'";
}

View File

@ -20,7 +20,7 @@ namespace SqlSugar
else
{
var type = value.GetType();
if (type == PubConst.DateType)
if (type == UtilConstants.DateType)
{
var date = value.ObjToDate();
if (date < Convert.ToDateTime("1900-1-1"))
@ -33,11 +33,11 @@ namespace SqlSugar
{
return Convert.ToInt64(value);
}
else if (type == PubConst.BoolType)
else if (type == UtilConstants.BoolType)
{
return value.ObjToBool() ? "1" : "0";
}
else if (type == PubConst.StringType || type == PubConst.ObjType)
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
{
return "'" + value.ToString().ToSqlFilter() + "'";
}

View File

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Data.Sqlite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

View File

@ -1,42 +0,0 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace SqlSugar
{
public partial class SqliteProvider : AdoProvider
{
public override void ExecuteBefore(string sql, SugarParameter[] parameters)
{
if (sql.IsValuable() && parameters.IsValuable())
{
foreach (var parameter in parameters)
{
//Compatible with.NET CORE parameters case
var name = parameter.ParameterName;
if (!sql.Contains(name) && Regex.IsMatch(sql, "(" + name + "$)" + "|(" + name + @"[ ,\,])", RegexOptions.IgnoreCase)) {
parameter.ParameterName=Regex.Match(sql, "(" + name + "$)" + "|(" + name + @"[ ,\,])", RegexOptions.IgnoreCase).Value;
}
}
}
if (this.IsEnableLogEvent)
{
Action<string, string> action = LogEventStarting;
if (action != null)
{
if (parameters == null || parameters.Length == 0)
{
action(sql, null);
}
else
{
action(sql, this.Context.RewritableMethods.SerializeObject(parameters.Select(it => new { key = it.ParameterName, value = it.Value.ObjToString() })));
}
}
}
}
}
}

View File

@ -31,6 +31,10 @@ namespace SqlSugar
{
base.Context = this;
base.CurrentConnectionConfig = config;
if (config.DbType == DbType.Oracle)
{
throw new Exception("Oracle developed 60%,to be continued ");
}
}
#endregion
@ -261,37 +265,37 @@ namespace SqlSugar
}
#region 9-12
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8,T9> Queryable<T, T2, T3, T4, T5, T6, T7, T8,T9>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8,T9, bool>> joinExpression) where T : class, new()
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, bool>> joinExpression) where T : class, new()
{
InitMppingInfo<T, T2, T3, T4, T5, T6, T8,T9>();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8),typeof(T9) };
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5, T6, T7, T8,T9>(base.CurrentConnectionConfig);
InitMppingInfo<T, T2, T3, T4, T5, T6, T8, T9>();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9) };
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9>(base.CurrentConnectionConfig);
base.CreateEasyQueryJoin(joinExpression, types, queryable);
queryable.Where(joinExpression);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9,T10> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9,T10>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9,T10, bool>> joinExpression) where T : class, new()
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool>> joinExpression) where T : class, new()
{
InitMppingInfo<T, T2, T3, T4, T5, T6, T8, T9,T10>();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9) ,typeof(T10)};
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9,T10>(base.CurrentConnectionConfig);
InitMppingInfo<T, T2, T3, T4, T5, T6, T8, T9, T10>();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10) };
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>(base.CurrentConnectionConfig);
base.CreateEasyQueryJoin(joinExpression, types, queryable);
queryable.Where(joinExpression);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10,T11> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10,T11>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10,T11, bool>> joinExpression) where T : class, new()
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, bool>> joinExpression) where T : class, new()
{
InitMppingInfo<T, T2, T3, T4, T5, T6, T8, T9, T10,T11>();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10),typeof(T11) };
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10,T11>(base.CurrentConnectionConfig);
InitMppingInfo<T, T2, T3, T4, T5, T6, T8, T9, T10, T11>();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11) };
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(base.CurrentConnectionConfig);
base.CreateEasyQueryJoin(joinExpression, types, queryable);
queryable.Where(joinExpression);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,T12> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, bool>> joinExpression) where T : class, new()
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, bool>> joinExpression) where T : class, new()
{
InitMppingInfo<T, T2, T3, T4, T5, T6, T8, T9, T10, T11, T12>();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11),typeof(T12) };
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11), typeof(T12) };
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(base.CurrentConnectionConfig);
base.CreateEasyQueryJoin(joinExpression, types, queryable);
queryable.Where(joinExpression);
@ -299,23 +303,31 @@ namespace SqlSugar
}
#endregion
public virtual List<T> UnionAll<T>(params ISugarQueryable<T>[] queryables) where T : class, new()
public virtual ISugarQueryable<T> UnionAll<T>(params ISugarQueryable<T>[] queryables) where T : class, new()
{
if (queryables.IsNullOrEmpty()) return new List<T>();
List<T> result = new List<T>();
Check.Exception(queryables.IsNullOrEmpty(), "UnionAll.queryables is null ");
int i = 1;
List<KeyValuePair<string, List<SugarParameter>>> allItems = new List<KeyValuePair<string, List<SugarParameter>>>();
foreach (var item in queryables)
{
var addItems = item.ToList();
if (addItems.IsValuable())
{
result.AddRange(addItems);
}
var sqlObj = item.ToSql();
string sql = sqlObj.Key;
UtilMethods.RepairReplicationParameters(ref sql, sqlObj.Value.ToArray(), i);
if (sqlObj.Value.IsValuable())
allItems.Add(new KeyValuePair<string, List<SugarParameter>>(sql, sqlObj.Value));
else
allItems.Add(new KeyValuePair<string, List<SugarParameter>>(sql, new List<SugarParameter>()));
i++;
}
return result;
var allSql = string.Join("UNION ALL \r\n", allItems.Select(it => it.Key));
var allParameters = allItems.SelectMany(it => it.Value).ToArray();
var resulut = this.Queryable<ExpandoObject>().AS(UtilMethods.GetPackTable(allSql, "unionTable"));
resulut.AddParameters(allParameters);
return resulut.Select<T>("*");
}
public virtual List<T> UnionAll<T>(List<ISugarQueryable<T>> queryables) where T : class, new()
public virtual ISugarQueryable<T> UnionAll<T>(List<ISugarQueryable<T>> queryables) where T : class, new()
{
if (queryables.IsNullOrEmpty()) return new List<T>();
Check.Exception(queryables.IsNullOrEmpty(), "UnionAll.queryables is null ");
return UnionAll(queryables.ToArray());
}
#endregion
@ -342,7 +354,7 @@ namespace SqlSugar
Check.Exception(columnDictionary == null || columnDictionary.Count == 0, "Insertable.columnDictionary can't be null");
var insertObject = this.RewritableMethods.DeserializeObject<T>(this.RewritableMethods.SerializeObject(columnDictionary));
var columns = columnDictionary.Select(it => it.Key).ToList();
return this.Insertable(insertObject).InsertColumns(it => columns.Any(c => it.Equals(c,StringComparison.CurrentCultureIgnoreCase))); ;
return this.Insertable(insertObject).InsertColumns(it => columns.Any(c => it.Equals(c, StringComparison.CurrentCultureIgnoreCase))); ;
}
public virtual IInsertable<T> Insertable<T>(dynamic insertDynamicObject) where T : class, new()
{
@ -353,10 +365,10 @@ namespace SqlSugar
}
else
{
var columns= ((object)insertDynamicObject).GetType().GetProperties().Select(it => it.Name).ToList();
var columns = ((object)insertDynamicObject).GetType().GetProperties().Select(it => it.Name).ToList();
Check.Exception(columns.IsNullOrEmpty(), "Insertable.updateDynamicObject can't be null");
T insertObject = this.RewritableMethods.DeserializeObject<T>(this.RewritableMethods.SerializeObject(insertDynamicObject));
return this.Insertable(insertObject).InsertColumns(it=> columns.Any(c=>it.Equals(c,StringComparison.CurrentCultureIgnoreCase)));
return this.Insertable(insertObject).InsertColumns(it => columns.Any(c => it.Equals(c, StringComparison.CurrentCultureIgnoreCase)));
}
}
#endregion

View File

@ -9,32 +9,33 @@ 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));
}
}
}

View File

@ -58,7 +58,6 @@ namespace SqlSugar
}
}
public static string NotSupportedArray
{
get

View File

@ -7,7 +7,6 @@ namespace SqlSugar
{
internal static class IsWhatExtensions
{
public static bool IsInRange(this int thisValue, int begin, int end)
{
return thisValue >= begin && thisValue <= end;

View File

@ -82,11 +82,4 @@ namespace SqlSugar
return method.ReflectedType;
}
}
public static class ReflectionCore
{
public static Assembly Load(string name)
{
return Assembly.Load(name);
}
}
}

View File

@ -4,10 +4,13 @@ using System.Linq;
using System.Text;
namespace SqlSugar
{
internal static class PubConst
internal static class UtilConstants
{
internal const string AssemblyName = "SqlSugar";
internal const string Space = " ";
internal const string AssemblyName = "SqlSugar";
internal const string OrderReplace = "{$:OrderByString:$}";
internal static Type StringType = typeof(string);
internal static Type ShortType = typeof(short);
internal static Type IntType = typeof(int);

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
namespace SqlSugar
{
public static class PubConvert
public static class UtilConvert
{
public static int ObjToInt(this object thisValue)
{

View File

@ -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)
@ -30,7 +30,6 @@ namespace SqlSugar
return reval;
}
private static string GetMessage(SqlSugarClient context, string message, string sql, object pars)
{
if (pars == null)
@ -43,16 +42,14 @@ namespace SqlSugar
return reval;
}
}
private static string GetMessage(string message, string sql)
{
var reval = GetLineMessage("message ", message) + GetLineMessage("ORM Sql", sql);
return reval;
}
private static string GetLineMessage(string key, string value)
{
return string.Format("{0} 【{1}】\r\n", key, value);
return string.Format("{0} '{1}' \r\n", key, value);
}
}
}

View File

@ -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())
@ -55,5 +54,25 @@ namespace SqlSugar
{
return (T)Convert.ChangeType(obj, typeof(T));
}
internal static void RepairReplicationParameters(ref string appendSql, SugarParameter[] parameters, int addIndex)
{
if (appendSql.IsValuable() && parameters.IsValuable())
{
foreach (var parameter in parameters.OrderByDescending(it => it.ParameterName.Length))
{
//Compatible with.NET CORE parameters case
var name = parameter.ParameterName;
string newName = name + addIndex;
appendSql = appendSql.Replace(name, newName);
parameter.ParameterName = newName;
}
}
}
internal static string GetPackTable(string sql, string shortName)
{
return string.Format(" ({0}) {1} ", sql, shortName);
}
}
}