mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-08 02:14:53 +08:00
Update Core
This commit is contained in:
@@ -306,13 +306,13 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual bool CreateIndex(string tableName, string[] columnNames, bool isUnique=false)
|
||||
{
|
||||
string sql = string.Format(CreateIndexSql,tableName,string.Join(",",columnNames), string.Join("_", columnNames), isUnique ? "UNIQUE" : "");
|
||||
string sql = string.Format(CreateIndexSql,tableName,string.Join(",",columnNames), string.Join("_", columnNames) + this.Context.CurrentConnectionConfig.IndexSuffix, isUnique ? "UNIQUE" : "");
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
public virtual bool CreateUniqueIndex(string tableName, string[] columnNames)
|
||||
{
|
||||
string sql = string.Format(CreateIndexSql, tableName, string.Join(",", columnNames), string.Join("_", columnNames)+"_Unique","UNIQUE" );
|
||||
string sql = string.Format(CreateIndexSql, tableName, string.Join(",", columnNames), string.Join("_", columnNames) + this.Context.CurrentConnectionConfig.IndexSuffix + "_Unique","UNIQUE" );
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
@@ -370,7 +370,7 @@ namespace SqlSugar
|
||||
foreach (var item in groups)
|
||||
{
|
||||
var columnNames = indexColumns.Where(it => it.IndexGroupNameList.Any(i => i.Equals(item, StringComparison.CurrentCultureIgnoreCase))).Select(it=>it.DbColumnName).ToArray();
|
||||
var indexName = string.Format("Index_{0}_{1}",entityInfo.DbTableName, string.Join("_", columnNames));
|
||||
var indexName = string.Format("Index_{0}_{1}"+this.Context.CurrentConnectionConfig.IndexSuffix,entityInfo.DbTableName, string.Join("_", columnNames));
|
||||
if (!IsAnyIndex(indexName))
|
||||
{
|
||||
CreateIndex(entityInfo.DbTableName, columnNames);
|
||||
@@ -386,7 +386,7 @@ namespace SqlSugar
|
||||
foreach (var item in groups)
|
||||
{
|
||||
var columnNames = uIndexColumns.Where(it => it.UIndexGroupNameList.Any(i => i.Equals(item, StringComparison.CurrentCultureIgnoreCase))).Select(it => it.DbColumnName).ToArray();
|
||||
var indexName = string.Format("Index_{0}_{1}_Unique", entityInfo.DbTableName, string.Join("_", columnNames));
|
||||
var indexName = string.Format("Index_{0}_{1}_Unique" + this.Context.CurrentConnectionConfig.IndexSuffix, entityInfo.DbTableName, string.Join("_", columnNames));
|
||||
if (!IsAnyIndex(indexName))
|
||||
{
|
||||
CreateUniqueIndex(entityInfo.DbTableName, columnNames);
|
||||
|
||||
@@ -669,24 +669,5 @@ namespace SqlSugar
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Obsolete
|
||||
[Obsolete]
|
||||
public IInsertable<T> InsertColumns(Func<string, bool> insertColumMethod)
|
||||
{
|
||||
this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => insertColumMethod(it.PropertyName)).ToList();
|
||||
return this;
|
||||
}
|
||||
[Obsolete]
|
||||
public IInsertable<T> IgnoreColumns(Func<string, bool> ignoreColumMethod)
|
||||
{
|
||||
this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => !ignoreColumMethod(it.PropertyName)).ToList();
|
||||
return this;
|
||||
}
|
||||
[Obsolete]
|
||||
public IInsertable<T> Where(bool ignoreNullColumn, bool isOffIdentity = false)
|
||||
{
|
||||
return IgnoreColumns(ignoreNullColumn, isOffIdentity);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,6 +129,12 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual ISugarQueryable<T> Mapper<TObject>(Expression<Func<T, List<TObject>>> mapperObject, Expression<Func<T, object>> mapperField)
|
||||
{
|
||||
Check.Exception(mapperObject.ReturnType.Name == "IList`1", "Mapper no support IList , Use List<T>");
|
||||
if (CallContext.MapperExpression.Value == null)
|
||||
{
|
||||
CallContext.MapperExpression.Value = new List<MapperExpression>();
|
||||
}
|
||||
CallContext.MapperExpression.Value.Add(new MapperExpression() { SqlBuilder = SqlBuilder, QueryBuilder = this.QueryBuilder, Type = MapperExpressionType.oneToN, FillExpression = mapperObject, MappingField1Expression = mapperField,Context = this.Context });
|
||||
return _Mapper<TObject>(mapperObject, mapperField);
|
||||
}
|
||||
public virtual ISugarQueryable<T> Mapper<TObject>(Expression<Func<T, TObject>> mapperObject, Expression<Func<T, object>> mapperField)
|
||||
@@ -609,15 +615,8 @@ namespace SqlSugar
|
||||
Check.Exception(this.MapperAction != null || this.MapperActionWithCache != null, "'Mapper’ needs to be written after ‘MergeTable’ ");
|
||||
Check.Exception(this.QueryBuilder.SelectValue.IsNullOrEmpty(), "MergeTable need to use Queryable.Select Method .");
|
||||
Check.Exception(this.QueryBuilder.Skip > 0 || this.QueryBuilder.Take > 0 || this.QueryBuilder.OrderByValue.HasValue(), "MergeTable Queryable cannot Take Skip OrderBy PageToList ");
|
||||
ToSqlBefore();
|
||||
var sql = QueryBuilder.ToSqlString();
|
||||
var tableName = this.SqlBuilder.GetPackTable(sql, "MergeTable");
|
||||
var mergeQueryable = this.Context.Queryable<ExpandoObject>();
|
||||
mergeQueryable.QueryBuilder.Parameters = QueryBuilder.Parameters;
|
||||
mergeQueryable.QueryBuilder.WhereIndex = QueryBuilder.WhereIndex + 1;
|
||||
mergeQueryable.QueryBuilder.JoinIndex = QueryBuilder.JoinIndex + 1;
|
||||
mergeQueryable.QueryBuilder.LambdaExpressions.ParameterIndex = QueryBuilder.LambdaExpressions.ParameterIndex;
|
||||
return mergeQueryable.AS(tableName).Select<T>("*");
|
||||
var sqlobj = this.ToSql();
|
||||
return this.Context.Queryable<T>().AS(SqlBuilder.GetPackTable(sqlobj.Key, "MergeTable")).AddParameters(sqlobj.Value).Select("*").With(SqlWith.Null);
|
||||
}
|
||||
|
||||
public ISugarQueryable<T> Distinct()
|
||||
@@ -3387,6 +3386,41 @@ namespace SqlSugar
|
||||
_GroupBy(expression);
|
||||
return this;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5> Having(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
this._Having(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2, T3, T4, T5> Having(Expression<Func<T, T2, bool>> expression)
|
||||
{
|
||||
this._Having(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2, T3, T4, T5> Having(Expression<Func<T, T2, T3, bool>> expression)
|
||||
{
|
||||
this._Having(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2, T3, T4, T5> Having(Expression<Func<T, T2, T3, T4, bool>> expression)
|
||||
{
|
||||
this._Having(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2, T3, T4,T5> Having(Expression<Func<T, T2, T3, T4, T5, bool>> expression)
|
||||
{
|
||||
this._Having(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2, T3, T4,T5> Having(string whereString, object whereObj)
|
||||
{
|
||||
base.Having(whereString, whereObj);
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
@@ -3774,6 +3808,46 @@ namespace SqlSugar
|
||||
_GroupBy(expression);
|
||||
return this;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6> Having(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
this._Having(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6> Having(Expression<Func<T, T2, bool>> expression)
|
||||
{
|
||||
this._Having(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6> Having(Expression<Func<T, T2, T3, bool>> expression)
|
||||
{
|
||||
this._Having(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6> Having(Expression<Func<T, T2, T3, T4, bool>> expression)
|
||||
{
|
||||
this._Having(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6> Having(Expression<Func<T, T2, T3, T4, T5, bool>> expression)
|
||||
{
|
||||
this._Having(expression);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6> Having(Expression<Func<T, T2, T3, T4, T5,T6, bool>> expression)
|
||||
{
|
||||
this._Having(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5,T6> Having(string whereString, object whereObj)
|
||||
{
|
||||
base.Having(whereString, whereObj);
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
|
||||
@@ -323,6 +323,23 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
internal string GetN()
|
||||
{
|
||||
var N = "N";
|
||||
if (_Context.CurrentConnectionConfig.MoreSettings != null && _Context.CurrentConnectionConfig.MoreSettings.DisableNvarchar)
|
||||
{
|
||||
N = "";
|
||||
}
|
||||
return N;
|
||||
}
|
||||
internal bool IsVarchar()
|
||||
{
|
||||
if (_Context.CurrentConnectionConfig.MoreSettings != null && _Context.CurrentConnectionConfig.MoreSettings.DisableNvarchar)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static void CheckDbDependency(ConnectionConfig config)
|
||||
{
|
||||
switch (config.DbType)
|
||||
|
||||
@@ -315,68 +315,7 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#region delete obj
|
||||
[Obsolete]
|
||||
public IUpdateable<T> UpdateColumns(Expression<Func<T, bool>> columns)
|
||||
{
|
||||
return this.SetColumns(columns);
|
||||
}
|
||||
[Obsolete]
|
||||
public IUpdateable<T> UpdateColumns(Expression<Func<T, T>> columns)
|
||||
{
|
||||
return this.SetColumns(columns);
|
||||
}
|
||||
[Obsolete]
|
||||
public IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns, Expression<Func<T, T>> columns)
|
||||
{
|
||||
return this.SetColumnsIF(isUpdateColumns, columns);
|
||||
}
|
||||
[Obsolete]
|
||||
public IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns, Expression<Func<T, bool>> columns)
|
||||
{
|
||||
return this.SetColumnsIF(isUpdateColumns, columns);
|
||||
}
|
||||
[Obsolete]
|
||||
public IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns, Func<string, bool> updateColumMethod)
|
||||
{
|
||||
if (isUpdateColumns)
|
||||
UpdateColumns(updateColumMethod);
|
||||
return this;
|
||||
}
|
||||
[Obsolete]
|
||||
public IUpdateable<T> UpdateColumns(Func<string, bool> updateColumMethod)
|
||||
{
|
||||
List<string> primaryKeys = GetPrimaryKeys();
|
||||
foreach (var item in this.UpdateBuilder.DbColumnInfoList)
|
||||
{
|
||||
var mappingInfo = primaryKeys.SingleOrDefault(i => item.DbColumnName.Equals(i, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (mappingInfo != null && mappingInfo.Any())
|
||||
{
|
||||
item.IsPrimarykey = true;
|
||||
}
|
||||
}
|
||||
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => updateColumMethod(it.PropertyName) || it.IsPrimarykey || it.IsIdentity).ToList();
|
||||
return this;
|
||||
}
|
||||
[Obsolete]
|
||||
public IUpdateable<T> IgnoreColumns(Func<string, bool> ignoreColumMethod)
|
||||
{
|
||||
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => !ignoreColumMethod(it.PropertyName)).ToList();
|
||||
return this;
|
||||
}
|
||||
[Obsolete("Use IUpdateable<T> IgnoreColumns(bool ignoreAllNullColumns, bool isOffIdentity = false);")]
|
||||
public IUpdateable<T> Where(bool isUpdateNull, bool IsOffIdentity = false)
|
||||
{
|
||||
UpdateBuilder.IsOffIdentity = IsOffIdentity;
|
||||
if (this.UpdateBuilder.LambdaExpressions == null)
|
||||
this.UpdateBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(this.Context.CurrentConnectionConfig);
|
||||
this.UpdateBuilder.IsNoUpdateNull = isUpdateNull;
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Helper
|
||||
private void AppendSets()
|
||||
|
||||
@@ -9,10 +9,8 @@ namespace SqlSugar
|
||||
{
|
||||
public bool IsAutoRemoveDataCache { get; set; }
|
||||
public bool IsWithNoLockQuery { get; set; }
|
||||
/// <summary>
|
||||
/// Some MYSQL databases do not support NVarchar set true
|
||||
/// </summary>
|
||||
public bool MySqlDisableNarvchar { get; set; }
|
||||
|
||||
public bool DisableNvarchar { get; set; }
|
||||
public bool PgSqlIsAutoToLower = true;
|
||||
public int DefaultCacheDurationInSeconds { get; set; }
|
||||
}
|
||||
|
||||
@@ -52,6 +52,8 @@ namespace SqlSugar
|
||||
/// </summary>
|
||||
public SugarDebugger Debugger { get; set; }
|
||||
|
||||
public string IndexSuffix { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public AopEvents AopEvents { get;set; }
|
||||
}
|
||||
|
||||
@@ -33,7 +33,19 @@ namespace SqlSugar
|
||||
|
||||
private void ResolveList()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var methodExpression = expression as MethodCallExpression;
|
||||
var callName = methodExpression.Method.Name;
|
||||
var exp= methodExpression.Arguments[0] as MemberExpression;
|
||||
ThrowTrue(exp == null);
|
||||
var childExpression = exp;
|
||||
MapperExpression mapper = GetMapperMany(exp);
|
||||
var fillInfo = GetFillInfoMany(childExpression, mapper);
|
||||
var mappingFild1Info = GetMappingFild1ManyInfo(childExpression, mapper);
|
||||
var mappingFild1Info2 = GetMappingFild2Info(childExpression, mapper);
|
||||
//var SelectInfo = GetSelectInfo(expression);
|
||||
this.context.InitMappingInfo(childExpression.Expression.Type);
|
||||
var entity = this.context.EntityMaintenance.GetEntityInfo(childExpression.Expression.Type);
|
||||
oneToMany(callName, entity, childExpression.Expression.ToString(), fillInfo, mappingFild1Info, mappingFild1Info2);
|
||||
}
|
||||
|
||||
private void ResolveMember()
|
||||
@@ -62,7 +74,7 @@ namespace SqlSugar
|
||||
}
|
||||
else if (isFillFild1SameType)
|
||||
{
|
||||
oneToMany();
|
||||
throw new NotSupportedException(expression.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -87,9 +99,31 @@ namespace SqlSugar
|
||||
.Select(sqlBuilder.GetTranslationColumnName(selectInfo.FieldName)).ToSql().Key;
|
||||
}
|
||||
|
||||
private void oneToMany()
|
||||
private void oneToMany(string methodName,EntityInfo mainEntity,string shortName,MapperExpressionInfo fillInfo, MapperExpressionInfo mappingFild1Info, MapperExpressionInfo mappingFild1Info2)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var pkColumn = mainEntity.Columns.FirstOrDefault(it=>it.IsPrimarykey==true);
|
||||
if (pkColumn == null)
|
||||
{
|
||||
pkColumn = mainEntity.Columns.FirstOrDefault();
|
||||
}
|
||||
var tableName = sqlBuilder.GetTranslationTableName(fillInfo.EntityInfo.DbTableName);
|
||||
var whereLeft = sqlBuilder.GetTranslationColumnName(mappingFild1Info.FieldString);
|
||||
var whereRight = sqlBuilder.GetTranslationColumnName(shortName+"."+pkColumn.DbColumnName);
|
||||
|
||||
if (methodName == "Any")
|
||||
{
|
||||
this.sql = " ("+this.context.Queryable<object>()
|
||||
.AS(tableName)
|
||||
.Where(string.Format(" {0}={1} ", whereLeft, whereRight))
|
||||
.Select("COUNT(1)").ToSql().Key+")>0 ";
|
||||
}
|
||||
else
|
||||
{
|
||||
this.sql = this.context.Queryable<object>()
|
||||
.AS(tableName)
|
||||
.Where(string.Format(" {0}={1} ", whereLeft, whereRight))
|
||||
.Select("COUNT(1)").ToSql().Key;
|
||||
}
|
||||
}
|
||||
|
||||
private MapperExpressionInfo GetSelectInfo(Expression expression)
|
||||
@@ -205,6 +239,55 @@ namespace SqlSugar
|
||||
return new MapperSql() { Sql = " (" + this.sql + ") " };
|
||||
}
|
||||
|
||||
private MapperExpression GetMapperMany(MemberExpression exp)
|
||||
{
|
||||
var mapper = mappers.Where(it => it.Type == MapperExpressionType.oneToN)
|
||||
.Reverse()
|
||||
.Where(it => (it.FillExpression as LambdaExpression).Body.ToString() == exp.ToString()).FirstOrDefault();
|
||||
ThrowTrue(mapper == null);
|
||||
return mapper;
|
||||
}
|
||||
private MapperExpressionInfo GetFillInfoMany(Expression childExpression, MapperExpression mapper)
|
||||
{
|
||||
this.querybuiler = mapper.QueryBuilder;
|
||||
this.context = mapper.Context;
|
||||
this.sqlBuilder = mapper.SqlBuilder;
|
||||
if (this.querybuiler.TableShortName.IsNullOrEmpty())
|
||||
{
|
||||
this.querybuiler.TableShortName = (childExpression as MemberExpression).Expression.ToString();
|
||||
}
|
||||
var type = (childExpression as MemberExpression).Type.GetGenericArguments()[0];
|
||||
this.context.InitMappingInfo(type);
|
||||
return new MapperExpressionInfo()
|
||||
{
|
||||
EntityInfo = this.context.EntityMaintenance.GetEntityInfo(type)
|
||||
};
|
||||
}
|
||||
private MapperExpressionInfo GetMappingFild1ManyInfo(Expression childExpression, MapperExpression mapper)
|
||||
{
|
||||
var exp = mapper.MappingField1Expression;
|
||||
var field = (exp as LambdaExpression).Body;
|
||||
if (field is UnaryExpression)
|
||||
{
|
||||
field = (field as UnaryExpression).Operand;
|
||||
}
|
||||
var type = ((field as MemberExpression).Expression).Type;
|
||||
this.context.InitMappingInfo(type);
|
||||
var name = (field as MemberExpression).Member.Name;
|
||||
var entity = this.context.EntityMaintenance.GetEntityInfo(type);
|
||||
var fieldName = entity.Columns.First(it => it.PropertyName == name).DbColumnName;
|
||||
//var array = (field as MemberExpression).ToString().Split('.').ToList();
|
||||
//array[array.Count() - 1] = fieldName;
|
||||
//var filedString = string.Join(".", array);
|
||||
return new MapperExpressionInfo()
|
||||
{
|
||||
Type = type,
|
||||
FieldName = fieldName,
|
||||
FieldString = fieldName,
|
||||
EntityInfo = entity
|
||||
};
|
||||
}
|
||||
|
||||
void Error01()
|
||||
{
|
||||
Check.Exception(mappers == null, ErrorMessage.GetThrowMessage(expression.ToString() + "no support", "当前表达式" + expression.ToString() + "必须在Mapper之后使用"));
|
||||
|
||||
@@ -154,6 +154,10 @@ namespace SqlSugar
|
||||
else if (item is BinaryExpression)
|
||||
{
|
||||
var result = GetNewExpressionValue(item);
|
||||
if (result.HasValue())
|
||||
{
|
||||
result = result.Replace(",", UtilConstants.ReplaceCommaKey);
|
||||
}
|
||||
this.Context.Result.Append(base.Context.GetEqString(memberName, result));
|
||||
}
|
||||
else if (item is MemberInitExpression)
|
||||
@@ -182,6 +186,11 @@ namespace SqlSugar
|
||||
throw new NotSupportedException("Not Supported " + item.ToString() + " " + ex.Message);
|
||||
}
|
||||
}
|
||||
else if (item is ConditionalExpression)
|
||||
{
|
||||
var result = GetNewExpressionValue(item);
|
||||
this.Context.Result.Append(base.Context.GetEqString(memberName, result));
|
||||
}
|
||||
}
|
||||
}
|
||||
private static bool IsConst(Expression item)
|
||||
|
||||
@@ -154,6 +154,12 @@ namespace SqlSugar
|
||||
try
|
||||
{
|
||||
var constValue = ExpressionTool.DynamicInvoke(express);
|
||||
if (constValue is MapperSql)
|
||||
{
|
||||
constValue = (constValue as MapperSql).Sql;
|
||||
base.AppendValue(parameter, isLeft, constValue);
|
||||
return;
|
||||
}
|
||||
parameter.BaseParameter.CommonTempData = constValue;
|
||||
var parameterName = base.AppendParameter(constValue);
|
||||
if (parameter.BaseParameter.CommonTempData != null && parameter.BaseParameter.CommonTempData.Equals(CommonTempDataType.Result))
|
||||
|
||||
@@ -496,6 +496,12 @@ namespace SqlSugar
|
||||
ISugarQueryable<T, T2, T3, T4, T5> GroupBy(Expression<Func<T, T2, T3, object>> expression);
|
||||
ISugarQueryable<T, T2, T3, T4, T5> GroupBy(Expression<Func<T, T2, T3, T4, object>> expression);
|
||||
ISugarQueryable<T, T2, T3, T4, T5> GroupBy(Expression<Func<T, T2, T3, T4, T5, object>> expression);
|
||||
new ISugarQueryable<T, T2, T3, T4,T5> Having(Expression<Func<T, bool>> expression);
|
||||
ISugarQueryable<T, T2, T3, T4,T5> Having(Expression<Func<T, T2, bool>> expression);
|
||||
ISugarQueryable<T, T2, T3, T4,T5> Having(Expression<Func<T, T2, T3, bool>> expression);
|
||||
ISugarQueryable<T, T2, T3, T4,T5> Having(Expression<Func<T, T2, T3, T4, bool>> expression);
|
||||
ISugarQueryable<T, T2, T3, T4, T5> Having(Expression<Func<T, T2, T3, T4,T5, bool>> expression);
|
||||
new ISugarQueryable<T, T2, T3, T4,T5> Having(string whereString, object parameters = null);
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
@@ -594,6 +600,13 @@ namespace SqlSugar
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6> GroupBy(Expression<Func<T, T2, T3, T4, object>> expression);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6> GroupBy(Expression<Func<T, T2, T3, T4, T5, object>> expression);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6> GroupBy(Expression<Func<T, T2, T3, T4, T5, T6, object>> expression);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5,T6> Having(Expression<Func<T, bool>> expression);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6> Having(Expression<Func<T, T2, bool>> expression);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6> Having(Expression<Func<T, T2, T3, bool>> expression);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6> Having(Expression<Func<T, T2, T3, T4, bool>> expression);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6> Having(Expression<Func<T, T2, T3, T4, T5, bool>> expression);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6> Having(Expression<Func<T, T2, T3, T4, T5,T6, bool>> expression);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6> Having(string whereString, object parameters = null);
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace SqlSugar
|
||||
bool InsertRange(List<T> insertObjs);
|
||||
bool InsertRange(T[] insertObjs);
|
||||
int InsertReturnIdentity(T insertObj);
|
||||
long InsertReturnBigIdentity(T insertObj);
|
||||
bool IsAny(Expression<Func<T, bool>> whereExpression);
|
||||
bool Update(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression);
|
||||
bool Update(T updateObj);
|
||||
@@ -61,6 +62,7 @@ namespace SqlSugar
|
||||
Task<bool> InsertRangeAsync(List<T> insertObjs);
|
||||
Task<bool> InsertRangeAsync(T[] insertObjs);
|
||||
Task<int> InsertReturnIdentityAsync(T insertObj);
|
||||
Task<long> InsertReturnBigIdentityAsync(T insertObj);
|
||||
Task<bool> IsAnyAsync(Expression<Func<T, bool>> whereExpression);
|
||||
Task<bool> UpdateAsync(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression);
|
||||
Task<bool> UpdateAsync(T updateObj);
|
||||
|
||||
@@ -89,27 +89,6 @@ namespace SqlSugar
|
||||
IUpdateable<T> RemoveDataCache();
|
||||
KeyValuePair<string,List<SugarParameter>> ToSql();
|
||||
void AddQueue();
|
||||
|
||||
|
||||
#region delete obj
|
||||
|
||||
[Obsolete("Use IUpdateable<T> UpdateColumns(string [] columns)")]
|
||||
IUpdateable<T> UpdateColumns(Func<string, bool> updateColumMethod);
|
||||
[Obsolete("Use IUpdateable<T> IgnoreColumns(string [] columns)")]
|
||||
IUpdateable<T> IgnoreColumns(Func<string, bool> ignoreColumMethod);
|
||||
[Obsolete("Use IUpdateable<T> IgnoreColumns(bool ignoreAllNullColumns, bool isOffIdentity = false);")]
|
||||
IUpdateable<T> Where(bool isNoUpdateNull, bool IsOffIdentity = false);
|
||||
[Obsolete("Use IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns,string [] columns")]
|
||||
IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns, Func<string, bool> updateColumMethod);
|
||||
[Obsolete("Use SetColumns(Expression<Func<T, bool>> columns)")]
|
||||
IUpdateable<T> UpdateColumns(Expression<Func<T, bool>> columns);
|
||||
[Obsolete("Use SetColumns(Expression<Func<T, T>> columns")]
|
||||
IUpdateable<T> UpdateColumns(Expression<Func<T, T>> columns);
|
||||
|
||||
[Obsolete("Use SetColumnsIF(bool isUpdateColumns, Expression<Func<T, T>> columns)")]
|
||||
IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns, Expression<Func<T, T>> columns);
|
||||
[Obsolete("Use SetColumnsIF(bool isUpdateColumns, Expression<Func<T, bool>> columns")]
|
||||
IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns, Expression<Func<T, bool>> columns);
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,14 +39,5 @@ namespace SqlSugar
|
||||
MySqlBlueCopy<T> UseMySql();
|
||||
void AddQueue();
|
||||
|
||||
#region Obsolete
|
||||
[Obsolete("use IgnoreColumns(string[] columns")]
|
||||
|
||||
IInsertable<T> IgnoreColumns(Func<string, bool> ignoreColumMethod);
|
||||
[Obsolete("use InsertColumns(string[] columns")]
|
||||
IInsertable<T> InsertColumns(Func<string, bool> insertColumMethod);
|
||||
[Obsolete("use IgnoreColumns(bool isNoInsertNull, bool isOffIdentity = false)")]
|
||||
IInsertable<T> Where(bool ignoreNullColumn, bool isOffIdentity = false);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +109,7 @@ namespace SqlSugar
|
||||
if (parameters == null || parameters.Length == 0) return null;
|
||||
DmParameter[] result = new DmParameter[parameters.Length];
|
||||
int index = 0;
|
||||
var isVarchar = this.Context.IsVarchar();
|
||||
foreach (var parameter in parameters)
|
||||
{
|
||||
if (parameter.Value == null) parameter.Value = DBNull.Value;
|
||||
@@ -134,6 +135,10 @@ namespace SqlSugar
|
||||
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName);
|
||||
this.OutputParameters.Add(sqlParameter);
|
||||
}
|
||||
if (isVarchar && sqlParameter.DbType == System.Data.DbType.String)
|
||||
{
|
||||
sqlParameter.DbType = System.Data.DbType.AnsiString;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -89,6 +89,7 @@ namespace SqlSugar
|
||||
if (parameters == null || parameters.Length == 0) return null;
|
||||
MySqlParameter[] result = new MySqlParameter[parameters.Length];
|
||||
int index = 0;
|
||||
var isVarchar = this.Context.IsVarchar();
|
||||
foreach (var parameter in parameters)
|
||||
{
|
||||
if (parameter.Value == null) parameter.Value = DBNull.Value;
|
||||
@@ -113,6 +114,10 @@ namespace SqlSugar
|
||||
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName);
|
||||
this.OutputParameters.Add(sqlParameter);
|
||||
}
|
||||
if (isVarchar && sqlParameter.DbType == System.Data.DbType.String)
|
||||
{
|
||||
sqlParameter.DbType = System.Data.DbType.AnsiString;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace SqlSugar
|
||||
public override object FormatValue(object value)
|
||||
{
|
||||
var n = "N";
|
||||
if (this.Context.CurrentConnectionConfig.MoreSettings != null && this.Context.CurrentConnectionConfig.MoreSettings.MySqlDisableNarvchar)
|
||||
if (this.Context.CurrentConnectionConfig.MoreSettings != null && this.Context.CurrentConnectionConfig.MoreSettings.DisableNvarchar)
|
||||
{
|
||||
n = "";
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace SqlSugar
|
||||
public override object FormatValue(object value)
|
||||
{
|
||||
var n = "N";
|
||||
if (this.Context.CurrentConnectionConfig.MoreSettings != null&&this.Context.CurrentConnectionConfig.MoreSettings.MySqlDisableNarvchar)
|
||||
if (this.Context.CurrentConnectionConfig.MoreSettings != null&&this.Context.CurrentConnectionConfig.MoreSettings.DisableNvarchar)
|
||||
{
|
||||
n = "";
|
||||
}
|
||||
|
||||
@@ -115,6 +115,7 @@ namespace SqlSugar
|
||||
if (parameters == null || parameters.Length == 0) return null;
|
||||
OracleParameter[] result = new OracleParameter[parameters.Length];
|
||||
int index = 0;
|
||||
var isVarchar = this.Context.IsVarchar();
|
||||
foreach (var parameter in parameters)
|
||||
{
|
||||
if (parameter.Value == null) parameter.Value = DBNull.Value;
|
||||
@@ -172,7 +173,10 @@ namespace SqlSugar
|
||||
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName);
|
||||
this.OutputParameters.Add(sqlParameter);
|
||||
}
|
||||
|
||||
if (isVarchar && sqlParameter.DbType == System.Data.DbType.String)
|
||||
{
|
||||
sqlParameter.DbType = System.Data.DbType.AnsiString;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -107,6 +107,7 @@ namespace SqlSugar
|
||||
}
|
||||
else
|
||||
{
|
||||
string N = this.Context.GetN();
|
||||
var type = UtilMethods.GetUnderType(value.GetType());
|
||||
if (type == UtilConstants.StringType && value.ToString().Contains("{SugarSeq:=}"))
|
||||
{
|
||||
@@ -136,11 +137,11 @@ namespace SqlSugar
|
||||
}
|
||||
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
|
||||
{
|
||||
return "N'" + value.ToString().ToSqlFilter() + "'";
|
||||
return N+"'" + value.ToString().ToSqlFilter() + "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "N'" + value.ToString() + "'";
|
||||
return N+"'" + value.ToString() + "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace SqlSugar
|
||||
}
|
||||
else
|
||||
{
|
||||
string N =this.Context.GetN();
|
||||
var type = UtilMethods.GetUnderType(value.GetType());
|
||||
if (type == UtilConstants.DateType)
|
||||
{
|
||||
@@ -69,11 +70,11 @@ namespace SqlSugar
|
||||
}
|
||||
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
|
||||
{
|
||||
return "N'" + value.ToString().ToSqlFilter() + "'";
|
||||
return N + "'" + value.ToString().ToSqlFilter() + "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "N'" + value.ToString() + "'";
|
||||
return N + "'" + value.ToString() + "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ namespace SqlSugar
|
||||
if (parameters == null || parameters.Length == 0) return null;
|
||||
NpgsqlParameter[] result = new NpgsqlParameter[parameters.Length];
|
||||
int index = 0;
|
||||
var isVarchar = this.Context.IsVarchar();
|
||||
foreach (var parameter in parameters)
|
||||
{
|
||||
if (parameter.Value == null) parameter.Value = DBNull.Value;
|
||||
@@ -123,6 +124,10 @@ namespace SqlSugar
|
||||
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName);
|
||||
this.OutputParameters.Add(sqlParameter);
|
||||
}
|
||||
if (isVarchar && sqlParameter.DbType == System.Data.DbType.String)
|
||||
{
|
||||
sqlParameter.DbType = System.Data.DbType.AnsiString;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -117,6 +117,7 @@ namespace SqlSugar
|
||||
/// <returns></returns>
|
||||
public SqlParameter[] GetSqlParameter(params SugarParameter[] parameters)
|
||||
{
|
||||
var isVarchar = this.Context.IsVarchar();
|
||||
if (parameters == null || parameters.Length == 0) return null;
|
||||
SqlParameter[] result = new SqlParameter[parameters.Length];
|
||||
int index = 0;
|
||||
@@ -150,6 +151,12 @@ namespace SqlSugar
|
||||
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName);
|
||||
this.OutputParameters.Add(sqlParameter);
|
||||
}
|
||||
|
||||
if (isVarchar&&sqlParameter.DbType== System.Data.DbType.String)
|
||||
{
|
||||
sqlParameter.DbType =System.Data.DbType.AnsiString;
|
||||
}
|
||||
|
||||
++index;
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -132,6 +132,10 @@ namespace SqlSugar
|
||||
{
|
||||
return this.Context.Insertable(insertObj).ExecuteReturnIdentity();
|
||||
}
|
||||
public virtual long InsertReturnBigIdentity(T insertObj)
|
||||
{
|
||||
return this.Context.Insertable(insertObj).ExecuteReturnBigIdentity();
|
||||
}
|
||||
public virtual bool InsertRange(T[] insertObjs)
|
||||
{
|
||||
return this.Context.Insertable(insertObjs).ExecuteCommand() > 0;
|
||||
@@ -238,6 +242,10 @@ namespace SqlSugar
|
||||
{
|
||||
return this.Context.Insertable(insertObj).ExecuteReturnIdentityAsync();
|
||||
}
|
||||
public virtual Task<long> InsertReturnBigIdentityAsync(T insertObj)
|
||||
{
|
||||
return this.Context.Insertable(insertObj).ExecuteReturnBigIdentityAsync();
|
||||
}
|
||||
public virtual async Task<bool> InsertRangeAsync(T[] insertObjs)
|
||||
{
|
||||
return await this.Context.Insertable(insertObjs).ExecuteCommandAsync() > 0;
|
||||
|
||||
@@ -940,6 +940,11 @@ namespace SqlSugar
|
||||
}
|
||||
private void AllClientEach(Action<ISqlSugarClient> action)
|
||||
{
|
||||
if (this._AllClients == null)
|
||||
{
|
||||
this._AllClients = new List<SugarTenant>();
|
||||
this._AllClients.Add(new SugarTenant() { ConnectionConfig=this.CurrentConnectionConfig, Context=this.Context });
|
||||
}
|
||||
if (_AllClients.HasValue())
|
||||
{
|
||||
foreach (var item in _AllClients.Where(it => it.Context.HasValue()))
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
namespace SqlSugar
|
||||
{
|
||||
public static class UtilConvert
|
||||
internal static class UtilConvert
|
||||
{
|
||||
public static int ObjToInt(this object thisValue)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
namespace SqlSugar.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
///Common Extensions for external users
|
||||
/// </summary>
|
||||
public static class UtilExtensions
|
||||
{
|
||||
public static int ObjToInt(this object thisValue)
|
||||
{
|
||||
int reval = 0;
|
||||
if (thisValue == null) return 0;
|
||||
if (thisValue is Enum)
|
||||
{
|
||||
return (int)thisValue;
|
||||
}
|
||||
if (thisValue != null && thisValue != DBNull.Value && int.TryParse(thisValue.ToString(), out reval))
|
||||
{
|
||||
return reval;
|
||||
}
|
||||
return reval;
|
||||
}
|
||||
|
||||
public static int ObjToInt(this object thisValue, int errorValue)
|
||||
{
|
||||
int reval = 0;
|
||||
if (thisValue is Enum)
|
||||
{
|
||||
return (int)thisValue;
|
||||
}
|
||||
if (thisValue != null && thisValue != DBNull.Value && int.TryParse(thisValue.ToString(), out reval))
|
||||
{
|
||||
return reval;
|
||||
}
|
||||
return errorValue;
|
||||
}
|
||||
|
||||
public static double ObjToMoney(this object thisValue)
|
||||
{
|
||||
double reval = 0;
|
||||
if (thisValue != null && thisValue != DBNull.Value && double.TryParse(thisValue.ToString(), out reval))
|
||||
{
|
||||
return reval;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static double ObjToMoney(this object thisValue, double errorValue)
|
||||
{
|
||||
double reval = 0;
|
||||
if (thisValue != null && thisValue != DBNull.Value && double.TryParse(thisValue.ToString(), out reval))
|
||||
{
|
||||
return reval;
|
||||
}
|
||||
return errorValue;
|
||||
}
|
||||
|
||||
public static string ObjToString(this object thisValue)
|
||||
{
|
||||
if (thisValue != null) return thisValue.ToString().Trim();
|
||||
return "";
|
||||
}
|
||||
|
||||
public static string ObjToString(this object thisValue, string errorValue)
|
||||
{
|
||||
if (thisValue != null) return thisValue.ToString().Trim();
|
||||
return errorValue;
|
||||
}
|
||||
|
||||
public static Decimal ObjToDecimal(this object thisValue)
|
||||
{
|
||||
Decimal reval = 0;
|
||||
if (thisValue != null && thisValue != DBNull.Value && decimal.TryParse(thisValue.ToString(), out reval))
|
||||
{
|
||||
return reval;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static Decimal ObjToDecimal(this object thisValue, decimal errorValue)
|
||||
{
|
||||
Decimal reval = 0;
|
||||
if (thisValue != null && thisValue != DBNull.Value && decimal.TryParse(thisValue.ToString(), out reval))
|
||||
{
|
||||
return reval;
|
||||
}
|
||||
return errorValue;
|
||||
}
|
||||
|
||||
public static DateTime ObjToDate(this object thisValue)
|
||||
{
|
||||
DateTime reval = DateTime.MinValue;
|
||||
if (thisValue != null && thisValue != DBNull.Value && DateTime.TryParse(thisValue.ToString(), out reval))
|
||||
{
|
||||
reval = Convert.ToDateTime(thisValue);
|
||||
}
|
||||
return reval;
|
||||
}
|
||||
|
||||
public static DateTime ObjToDate(this object thisValue, DateTime errorValue)
|
||||
{
|
||||
DateTime reval = DateTime.MinValue;
|
||||
if (thisValue != null && thisValue != DBNull.Value && DateTime.TryParse(thisValue.ToString(), out reval))
|
||||
{
|
||||
return reval;
|
||||
}
|
||||
return errorValue;
|
||||
}
|
||||
|
||||
public static bool ObjToBool(this object thisValue)
|
||||
{
|
||||
bool reval = false;
|
||||
if (thisValue != null && thisValue != DBNull.Value && bool.TryParse(thisValue.ToString(), out reval))
|
||||
{
|
||||
return reval;
|
||||
}
|
||||
return reval;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user