mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 01:58:13 +08:00
Update Core
This commit is contained in:
@@ -86,13 +86,13 @@ namespace SqlSugar
|
||||
if (tables == null) return false;
|
||||
else return tables.Any(it => it.Name.Equals(tableName, StringComparison.CurrentCultureIgnoreCase));
|
||||
}
|
||||
public virtual bool IsAnyColumn(string tableName, string columnName)
|
||||
public virtual bool IsAnyColumn(string tableName, string columnName, bool isCache = true)
|
||||
{
|
||||
columnName = this.SqlBuilder.GetNoTranslationColumnName(columnName);
|
||||
tableName = this.SqlBuilder.GetNoTranslationColumnName(tableName);
|
||||
var isAny = IsAnyTable(tableName);
|
||||
var isAny = IsAnyTable(tableName,isCache);
|
||||
Check.Exception(!isAny, string.Format("Table {0} does not exist", tableName));
|
||||
var columns = GetColumnInfosByTableName(tableName);
|
||||
var columns = GetColumnInfosByTableName(tableName,isCache);
|
||||
if (columns.IsNullOrEmpty()) return false;
|
||||
return columns.Any(it => it.DbColumnName.Equals(columnName, StringComparison.CurrentCultureIgnoreCase));
|
||||
}
|
||||
|
@@ -460,6 +460,10 @@ namespace SqlSugar
|
||||
|
||||
public virtual T InSingle(object pkValue)
|
||||
{
|
||||
if (pkValue == null)
|
||||
{
|
||||
pkValue = -1;
|
||||
}
|
||||
Check.Exception(this.QueryBuilder.SelectValue.HasValue(), "'InSingle' and' Select' can't be used together,You can use .Select(it=>...).Single(it.id==1)");
|
||||
var list = In(pkValue).ToList();
|
||||
if (list == null) return default(T);
|
||||
@@ -887,6 +891,19 @@ namespace SqlSugar
|
||||
{
|
||||
return this.Context.Utilities.SerializeObject(this.ToPageList(pageIndex, pageSize, ref totalNumber), typeof(T));
|
||||
}
|
||||
public virtual DataTable ToPivotTable<TColumn, TRow, TData>(Func<T, TColumn> columnSelector, Expression<Func<T, TRow>> rowSelector, Func<IEnumerable<T>, TData> dataSelector)
|
||||
{
|
||||
return this.ToList().ToPivotTable(columnSelector,rowSelector,dataSelector);
|
||||
}
|
||||
public virtual List<dynamic> ToPivotList<TColumn, TRow, TData>(Func<T, TColumn> columnSelector, Expression<Func<T, TRow>> rowSelector, Func<IEnumerable<T>, TData> dataSelector)
|
||||
{
|
||||
return this.ToList().ToPivotList(columnSelector, rowSelector, dataSelector);
|
||||
}
|
||||
public virtual string ToPivotJson<TColumn, TRow, TData>(Func<T, TColumn> columnSelector, Expression<Func<T, TRow>> rowSelector, Func<IEnumerable<T>, TData> dataSelector)
|
||||
{
|
||||
var list= this.ToPivotList(columnSelector, rowSelector, dataSelector);
|
||||
return this.Context.Utilities.SerializeObject(list);
|
||||
}
|
||||
public List<T> ToParentList(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue)
|
||||
{
|
||||
List<T> result = new List<T>() { };
|
||||
@@ -2259,6 +2276,7 @@ namespace SqlSugar
|
||||
asyncQueryableBuilder.LambdaExpressions.ParameterIndex = this.QueryBuilder.LambdaExpressions.ParameterIndex;
|
||||
asyncQueryableBuilder.IgnoreColumns = this.QueryBuilder.IgnoreColumns;
|
||||
asyncQueryableBuilder.AsTables = this.QueryBuilder.AsTables;
|
||||
asyncQueryableBuilder.DisableTop = this.QueryBuilder.DisableTop;
|
||||
}
|
||||
protected int SetCacheTime(int cacheDurationInSeconds)
|
||||
{
|
||||
|
@@ -31,6 +31,20 @@ namespace SqlSugar
|
||||
public MappingColumnList MappingColumns { get; set; }
|
||||
public IgnoreColumnList IgnoreColumns { get; set; }
|
||||
public IgnoreColumnList IgnoreInsertColumns { get; set; }
|
||||
public ConfigQuery ConfigQuery {
|
||||
get
|
||||
{
|
||||
if (_SqlConfigTable==null)
|
||||
{
|
||||
_SqlConfigTable = new ConfigQuery() { Context = this.Context };
|
||||
}
|
||||
return _SqlConfigTable;
|
||||
}
|
||||
set
|
||||
{
|
||||
_SqlConfigTable = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
@@ -46,7 +60,8 @@ namespace SqlSugar
|
||||
protected IContextMethods _RewritableMethods;
|
||||
protected IDbMaintenance _DbMaintenance;
|
||||
protected QueryFilterProvider _QueryFilterProvider;
|
||||
protected SimpleClient _SimpleClient;
|
||||
protected ConfigQuery _SqlConfigTable;
|
||||
//protected SimpleClient _SimpleClient;
|
||||
protected IAdo ContextAdo
|
||||
{
|
||||
get
|
||||
|
@@ -828,16 +828,16 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region SimpleClient
|
||||
[Obsolete("Use SqlSugarClient.GetSimpleClient() Or SqlSugarClient.GetSimpleClient<T>() ")]
|
||||
public virtual SimpleClient SimpleClient
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._SimpleClient == null)
|
||||
this._SimpleClient = new SimpleClient(this);
|
||||
return this._SimpleClient;
|
||||
}
|
||||
}
|
||||
//[Obsolete("Use SqlSugarClient.GetSimpleClient() Or SqlSugarClient.GetSimpleClient<T>() ")]
|
||||
//public virtual SimpleClient SimpleClient
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// if (this._SimpleClient == null)
|
||||
// this._SimpleClient = new SimpleClient(this);
|
||||
// return this._SimpleClient;
|
||||
// }
|
||||
//}
|
||||
public virtual SimpleClient<T> GetSimpleClient<T>() where T : class, new()
|
||||
{
|
||||
return new SimpleClient<T>(this);
|
||||
|
@@ -34,6 +34,7 @@ namespace SqlSugar
|
||||
public DiffLogModel diffModel { get; set; }
|
||||
private Action RemoveCacheFunc { get; set; }
|
||||
private int SetColumnsIndex { get; set; }
|
||||
private List<DbColumnInfo> columns { get; set; }
|
||||
#endregion
|
||||
|
||||
#region Core
|
||||
@@ -207,6 +208,7 @@ namespace SqlSugar
|
||||
if (this.WhereColumnList == null) this.WhereColumnList = new List<string>();
|
||||
foreach (var item in whereColumns)
|
||||
{
|
||||
_WhereColumn(item);
|
||||
this.WhereColumnList.Add(item);
|
||||
}
|
||||
return this;
|
||||
@@ -216,15 +218,18 @@ namespace SqlSugar
|
||||
|
||||
ThrowUpdateByExpression();
|
||||
if (this.WhereColumnList == null) this.WhereColumnList = new List<string>();
|
||||
_WhereColumn(columnName);
|
||||
this.WhereColumnList.Add(columnName);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IUpdateable<T> WhereColumns(string[] columnNames)
|
||||
{
|
||||
ThrowUpdateByExpression();
|
||||
if (this.WhereColumnList == null) this.WhereColumnList = new List<string>();
|
||||
foreach (var columnName in columnNames)
|
||||
{
|
||||
_WhereColumn(columnName);
|
||||
this.WhereColumnList.Add(columnName);
|
||||
}
|
||||
return this;
|
||||
@@ -302,6 +307,10 @@ namespace SqlSugar
|
||||
Check.Exception(!(binaryExp.Left is MemberExpression) && !(binaryExp.Left is UnaryExpression), "No support {0}", columns.ToString());
|
||||
Check.Exception(ExpressionTool.IsConstExpression(binaryExp.Left as MemberExpression), "No support {0}", columns.ToString());
|
||||
var expResult = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.WhereSingle).GetResultString().Replace(")", " )").Replace("(", "( ").Trim().TrimStart('(').TrimEnd(')');
|
||||
if (expResult.EndsWith(" IS NULL "))
|
||||
{
|
||||
expResult = Regex.Split(expResult, " IS NULL ")[0]+" = NULL ";
|
||||
}
|
||||
string key = SqlBuilder.GetNoTranslationColumnName(expResult);
|
||||
UpdateBuilder.SetValues.Add(new KeyValuePair<string, string>(SqlBuilder.GetTranslationColumnName(key), expResult));
|
||||
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => (UpdateParameterIsNull == false && IsPrimaryKey(it)) || UpdateBuilder.SetValues.Any(v => SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase) || SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase)) || it.IsPrimarykey == true).ToList();
|
||||
@@ -388,6 +397,16 @@ namespace SqlSugar
|
||||
Before(sql);
|
||||
return sql;
|
||||
}
|
||||
|
||||
private void _WhereColumn(string columnName)
|
||||
{
|
||||
var columnInfos = columns.Where(it => it.DbColumnName.Equals(columnName, StringComparison.OrdinalIgnoreCase) || it.PropertyName.Equals(columnName, StringComparison.OrdinalIgnoreCase)).ToList();
|
||||
if (!this.UpdateBuilder.DbColumnInfoList.Any(y => y.DbColumnName == columnInfos.First().DbColumnName))
|
||||
{
|
||||
this.UpdateBuilder.DbColumnInfoList.AddRange(columnInfos);
|
||||
}
|
||||
}
|
||||
|
||||
private void AutoRemoveDataCache()
|
||||
{
|
||||
var moreSetts = this.Context.CurrentConnectionConfig.MoreSettings;
|
||||
@@ -424,6 +443,7 @@ namespace SqlSugar
|
||||
}
|
||||
++i;
|
||||
}
|
||||
this.columns = this.UpdateBuilder.DbColumnInfoList;
|
||||
}
|
||||
private void CheckTranscodeing(bool checkIsJson = true)
|
||||
{
|
||||
|
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class ConfigQuery
|
||||
{
|
||||
public SqlSugarProvider Context { get; set; }
|
||||
public void SetTable<T>(Expression<Func<T, object>> keyExpression, Expression<Func<T, object>> valueTextExpression, string uniqueCode = null, Expression<Func<T, object>> whereExpression=null)
|
||||
{
|
||||
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||
ExpressionContext context = new ExpressionContext();
|
||||
var query = Context.Queryable<T>().QueryBuilder;
|
||||
var keyValue= query.GetExpressionValue(keyExpression, ResolveExpressType.FieldSingle).GetString();
|
||||
var ValueValue = query.GetExpressionValue(valueTextExpression, ResolveExpressType.FieldSingle).GetString();
|
||||
string where = null;
|
||||
if (whereExpression != null)
|
||||
{
|
||||
where=query.GetExpressionValue(whereExpression, ResolveExpressType.WhereSingle).GetResultString();
|
||||
}
|
||||
context.MappingTables = this.Context.MappingTables;
|
||||
if (!SqlFuncExtendsion.TableInfos.Any(y => y.Type == typeof(T) && y.Code == uniqueCode))
|
||||
{
|
||||
SqlFuncExtendsion.TableInfos.Add(new ConfigTableInfo()
|
||||
{
|
||||
Type = typeof(T),
|
||||
TableName = entity.DbTableName,
|
||||
Key = keyValue,
|
||||
Value = ValueValue,
|
||||
Where = where,
|
||||
Parameter = query.Parameters,
|
||||
Code = uniqueCode
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Check.Exception(true, "SetKeyValue error , entity & uniqueCode already exist");
|
||||
}
|
||||
}
|
||||
public void SetTable<T>(Expression<Func<T, object>> key, Expression<Func<T, object>> value)
|
||||
{
|
||||
SetTable<T>(key,value, null,null);
|
||||
}
|
||||
|
||||
public bool Any()
|
||||
{
|
||||
return SqlFuncExtendsion.TableInfos.Any();
|
||||
}
|
||||
}
|
||||
|
||||
public class ConfigTableInfo
|
||||
{
|
||||
public string Code { get; set; }
|
||||
public Type Type { get; set; }
|
||||
public string TableName { get; set; }
|
||||
public string Key { get; set; }
|
||||
public string Value { get; set; }
|
||||
public string Where { get; set; }
|
||||
public List<SugarParameter> Parameter { get; set; }
|
||||
}
|
||||
}
|
@@ -192,4 +192,15 @@ namespace SqlSugar
|
||||
|
||||
}
|
||||
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = true)]
|
||||
public class TenantAttribute :Attribute
|
||||
{
|
||||
public object configId { get; set; }
|
||||
public TenantAttribute(object configId)
|
||||
{
|
||||
this.configId = configId;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -171,6 +171,25 @@ namespace SqlSugar
|
||||
return reval;
|
||||
}
|
||||
|
||||
internal static object GetExpressionValue(Expression expression)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (expression is ConstantExpression)
|
||||
{
|
||||
return (expression as ConstantExpression).Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetMemberValue((expression as MemberExpression).Member, expression);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return LambdaExpression.Lambda(expression).Compile().DynamicInvoke();
|
||||
}
|
||||
}
|
||||
|
||||
public static object GetFiledValue(MemberExpression memberExpr)
|
||||
{
|
||||
if (!(memberExpr.Member is FieldInfo))
|
||||
|
@@ -212,7 +212,14 @@ namespace SqlSugar
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
var parameter2 = model.Args[1];
|
||||
return string.Format(" DateName({0},{1}) ", parameter2.MemberValue, parameter.MemberName);
|
||||
if (parameter.MemberName != null && parameter.MemberName is DateTime)
|
||||
{
|
||||
return string.Format(" DateName({0},'{1}') ", parameter2.MemberValue, parameter.MemberName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Format(" DateName({0},{1}) ", parameter2.MemberValue, parameter.MemberName);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string ToInt32(MethodCallExpressionModel model)
|
||||
|
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public static class SqlFuncExtendsion
|
||||
{
|
||||
internal static List<ConfigTableInfo> TableInfos = new List<ConfigTableInfo>();
|
||||
public static string GetConfigValue<Type>(this object field)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
public static string GetConfigValue<Type>(this object field,string uniqueCode)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
|
||||
public static FieldType SelectAll<FieldType>(this FieldType field)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
}
|
||||
}
|
@@ -139,8 +139,16 @@ namespace SqlSugar
|
||||
if (addItem.Value == null && dataType == UtilConstants.DateType)
|
||||
{
|
||||
addItem.DbType = System.Data.DbType.Date;
|
||||
|
||||
}
|
||||
if (addItem.Value == null && dataType.IsIn(UtilConstants.FloatType,UtilConstants.IntType,UtilConstants.LongType,UtilConstants.DecType,UtilConstants.DobType))
|
||||
{
|
||||
addItem.DbType = System.Data.DbType.Int32;
|
||||
}
|
||||
if (addItem.Value == null && dataType == UtilConstants.BoolType)
|
||||
{
|
||||
addItem.DbType = System.Data.DbType.Boolean;
|
||||
}
|
||||
|
||||
this.Context.Parameters.Add(addItem);
|
||||
this.Context.ParameterIndex++;
|
||||
}
|
||||
|
@@ -46,6 +46,11 @@ namespace SqlSugar
|
||||
this.Context.Result.Append(this.Context.DbMehtods.GuidNew());
|
||||
return;
|
||||
}
|
||||
else if (methodName == "GetConfigValue")
|
||||
{
|
||||
GetConfigValue(express,parameter);
|
||||
return;
|
||||
}
|
||||
else if (IsSubMethod(express, methodName))
|
||||
{
|
||||
//Check.Exception(!(parameter.BaseExpression is BinaryExpression), "Current expressions are not supported");
|
||||
@@ -95,6 +100,58 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
|
||||
private void GetConfigValue(MethodCallExpression express,ExpressionParameter parameter)
|
||||
{
|
||||
var exp = express.Arguments[0];
|
||||
var name =Regex.Match(express.Method.ToString(), @"GetConfigValue\[(.+)\]").Groups[1].Value;
|
||||
string code = null;
|
||||
if (express.Arguments.Count > 1)
|
||||
{
|
||||
code=ExpressionTool.GetExpressionValue(express.Arguments[1])+"";
|
||||
}
|
||||
var entity= SqlFuncExtendsion.TableInfos.FirstOrDefault(y => y.Type.Name == name&&y.Code== code);
|
||||
Check.Exception(entity == null,string.Format( "GetConfigValue no configuration Entity={0} UniqueCode={1}",name,code));
|
||||
string sql = " (SELECT {0} FROM {1} WHERE {2}={3}";
|
||||
if (ExpressionTool.IsUnConvertExpress(exp))
|
||||
{
|
||||
exp = (exp as UnaryExpression).Operand;
|
||||
}
|
||||
var member = exp as MemberExpression;
|
||||
var it = member.Expression;
|
||||
var type = it.Type;
|
||||
var properyName =member.Member.Name;
|
||||
var eqName = string.Format("{0}.{1}",this.Context.GetTranslationColumnName(it.ToString()), this.Context.GetDbColumnName(type.Name,properyName));
|
||||
if (this.Context.IsSingle)
|
||||
{
|
||||
this.Context.SingleTableNameSubqueryShortName = it.ToString();
|
||||
}
|
||||
sql = string.Format(sql,entity.Value,this.Context.GetTranslationColumnName(entity.TableName),entity.Key, eqName);
|
||||
if (entity.Parameter != null)
|
||||
{
|
||||
foreach (var item in entity.Parameter)
|
||||
{
|
||||
var oldName = item.ParameterName;
|
||||
item.ParameterName = oldName + "_con_" + this.Context.ParameterIndex;
|
||||
entity.Where = entity.Where.Replace(oldName, item.ParameterName);
|
||||
}
|
||||
this.Context.ParameterIndex++;
|
||||
this.Context.Parameters.AddRange(entity.Parameter);
|
||||
}
|
||||
if (entity.Where.HasValue())
|
||||
{
|
||||
sql += " AND " + entity.Where;
|
||||
}
|
||||
sql += " )";
|
||||
if (this.Context.ResolveType.IsIn(ResolveExpressType.SelectMultiple, ResolveExpressType.SelectSingle, ResolveExpressType.Update))
|
||||
{
|
||||
parameter.BaseParameter.CommonTempData = sql;
|
||||
}
|
||||
else
|
||||
{
|
||||
AppendMember(parameter, parameter.IsLeft, sql);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsValidNativeMethod(MethodCallExpression express, string methodName)
|
||||
{
|
||||
return MethodMapping.ContainsKey(methodName) && express.Method.DeclaringType.Namespace == ("System");
|
||||
@@ -220,7 +277,7 @@ namespace SqlSugar
|
||||
}
|
||||
protected void Select(ExpressionParameter parameter, bool? isLeft, string name, IEnumerable<Expression> args, MethodCallExpressionModel model, List<MethodCallExpressionArgs> appendArgs = null)
|
||||
{
|
||||
if (name == "GetSelfAndAutoFill")
|
||||
if (name.IsIn("GetSelfAndAutoFill","SelectAll"))
|
||||
{
|
||||
var memberValue = (args.First() as MemberExpression).Expression.ToString();
|
||||
model.Args.Add(new MethodCallExpressionArgs() { MemberValue = memberValue, IsMember = true, MemberName = memberValue });
|
||||
@@ -665,6 +722,7 @@ namespace SqlSugar
|
||||
return this.Context.DbMehtods.IsNull(model);
|
||||
case "MergeString":
|
||||
return this.Context.DbMehtods.MergeString(model.Args.Select(it => it.MemberName.ObjToString()).ToArray());
|
||||
case "SelectAll":
|
||||
case "GetSelfAndAutoFill":
|
||||
this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
|
||||
return this.Context.DbMehtods.GetSelfAndAutoFill(model.Args[0].MemberValue.ObjToString(), this.Context.IsSingle);
|
||||
@@ -704,6 +762,10 @@ namespace SqlSugar
|
||||
}
|
||||
private bool CheckMethod(MethodCallExpression expression)
|
||||
{
|
||||
if (expression.Method.Name=="SelectAll")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (IsExtMethod(expression.Method.Name))
|
||||
return true;
|
||||
if (IsParseMethod(expression))
|
||||
@@ -753,7 +815,26 @@ namespace SqlSugar
|
||||
formatString = formatString.Replace("yy", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);
|
||||
|
||||
parameters.Args.Last().MemberValue = DateType.Month;
|
||||
formatString = formatString.Replace("MM", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);
|
||||
if (IsMySql())
|
||||
{
|
||||
formatString = formatString.Replace("MM", begin + UtilMethods.ConvertStringToNumbers("LPAD(" + this.GetMethodValue("DateValue", parameters).ObjToString() + ",2,0)") + end);
|
||||
}
|
||||
else if (IsSqlite())
|
||||
{
|
||||
formatString = formatString.Replace("MM", begin + UtilMethods.ConvertStringToNumbers("SUBSTR('00' ||" + this.GetMethodValue("DateValue", parameters).ObjToString() + ", -2, 2)") + end);
|
||||
}
|
||||
else if (IsPg())
|
||||
{
|
||||
formatString = formatString.Replace("MM", begin + UtilMethods.ConvertStringToNumbers("lpad(cast(" + this.GetMethodValue("DateValue", parameters).ObjToString() + " as varchar(20)),2,'0')") + end);
|
||||
}
|
||||
else if (IsOracle())
|
||||
{
|
||||
formatString = formatString.Replace("MM", begin + UtilMethods.ConvertStringToNumbers("lpad(cast(" + this.GetMethodValue("DateValue", parameters).ObjToString() + " as varchar(20)),2,'0')") + end);
|
||||
}
|
||||
else
|
||||
{
|
||||
formatString = formatString.Replace("MM", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);
|
||||
}
|
||||
formatString = formatString.Replace("M", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);
|
||||
|
||||
parameters.Args.Last().MemberValue = DateType.Day;
|
||||
@@ -772,8 +853,12 @@ namespace SqlSugar
|
||||
formatString = formatString.Replace("ss", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);
|
||||
formatString = formatString.Replace("s", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);
|
||||
|
||||
parameters.Args.Last().MemberValue = DateType.Millisecond;
|
||||
formatString = formatString.Replace("ms", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);
|
||||
if (!IsSqlite())
|
||||
{
|
||||
parameters.Args.Last().MemberValue = DateType.Millisecond;
|
||||
formatString = formatString.Replace("ms", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);
|
||||
}
|
||||
|
||||
var items = Regex.Matches(formatString, @"\^\d+\$").Cast<Match>().ToList();
|
||||
foreach (var item in items)
|
||||
{
|
||||
@@ -805,5 +890,23 @@ namespace SqlSugar
|
||||
}
|
||||
return this.GetMethodValue("MergeString", joinStringParameter).ObjToString();
|
||||
}
|
||||
|
||||
private bool IsMySql()
|
||||
{
|
||||
return this.Context is MySqlExpressionContext;
|
||||
}
|
||||
private bool IsSqlite()
|
||||
{
|
||||
return this.Context is SqliteExpressionContext;
|
||||
}
|
||||
private bool IsPg()
|
||||
{
|
||||
return this.Context is PostgreSQLExpressionContext;
|
||||
}
|
||||
private bool IsOracle()
|
||||
{
|
||||
return this.Context is OracleExpressionContext;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ namespace SqlSugar
|
||||
|
||||
#region Check
|
||||
bool IsAnyTable(string tableName, bool isCache = true);
|
||||
bool IsAnyColumn(string tableName, string column);
|
||||
bool IsAnyColumn(string tableName, string column, bool isCache = true);
|
||||
bool IsPrimaryKey(string tableName, string column);
|
||||
bool IsIdentity(string tableName, string column);
|
||||
bool IsAnyConstraint(string ConstraintName);
|
||||
|
@@ -166,6 +166,9 @@ namespace SqlSugar
|
||||
void AddQueue();
|
||||
ISugarQueryable<T> IgnoreColumns(Expression<Func<T, object>> columns);
|
||||
ISugarQueryable<T> IgnoreColumns(params string[] columns);
|
||||
DataTable ToPivotTable<TColumn, TRow, TData>(Func<T, TColumn> columnSelector,Expression<Func<T, TRow>> rowSelector,Func<IEnumerable<T>, TData> dataSelector);
|
||||
List<dynamic> ToPivotList<TColumn, TRow, TData>(Func<T, TColumn> columnSelector, Expression<Func<T, TRow>> rowSelector, Func<IEnumerable<T>, TData> dataSelector);
|
||||
string ToPivotJson<TColumn, TRow, TData>(Func<T, TColumn> columnSelector, Expression<Func<T, TRow>> rowSelector, Func<IEnumerable<T>, TData> dataSelector);
|
||||
}
|
||||
public partial interface ISugarQueryable<T, T2> : ISugarQueryable<T>
|
||||
{
|
||||
|
@@ -8,6 +8,7 @@ namespace SqlSugar
|
||||
public interface ISimpleClient<T> where T : class, new()
|
||||
{
|
||||
SimpleClient<ChangeType> Change<ChangeType>() where ChangeType : class, new();
|
||||
RepositoryType ChangeRepository<RepositoryType>() where RepositoryType : ISugarRepository ;
|
||||
IDeleteable<T> AsDeleteable();
|
||||
IInsertable<T> AsInsertable(List<T> insertObjs);
|
||||
IInsertable<T> AsInsertable(T insertObj);
|
||||
|
@@ -13,7 +13,7 @@ namespace SqlSugar
|
||||
IgnoreColumnList IgnoreColumns { get; set; }
|
||||
IgnoreColumnList IgnoreInsertColumns { get; set; }
|
||||
Dictionary<string, object> TempItems { get; set; }
|
||||
|
||||
ConfigQuery ConfigQuery { get; set; }
|
||||
|
||||
bool IsSystemTablesConfig { get; }
|
||||
Guid ContextID { get; set; }
|
||||
|
@@ -42,7 +42,7 @@ namespace SqlSugar
|
||||
/// <returns></returns>
|
||||
IUpdateable<T> WhereColumns(Expression<Func<T, object>> columns);
|
||||
IUpdateable<T> WhereColumns(string columnName);
|
||||
IUpdateable<T> WhereColumns(string [] columnNames);
|
||||
IUpdateable<T> WhereColumns(params string [] columnNames);
|
||||
|
||||
/// <summary>
|
||||
/// .UpdateColumns(it=>new{ it.Name,it.Price})
|
||||
|
@@ -31,7 +31,9 @@ namespace SqlSugar
|
||||
THEN true ELSE false END AS `IsPrimaryKey`,
|
||||
CASE WHEN EXTRA='auto_increment' THEN true ELSE false END as IsIdentity,
|
||||
CASE WHEN is_nullable = 'YES'
|
||||
THEN true ELSE false END AS `IsNullable`
|
||||
THEN true ELSE false END AS `IsNullable`,
|
||||
numeric_scale as Scale,
|
||||
numeric_scale as DecimalDigits
|
||||
FROM
|
||||
Information_schema.columns where TABLE_NAME='{0}' and TABLE_SCHEMA=(select database()) ORDER BY TABLE_NAME";
|
||||
return sql;
|
||||
|
@@ -48,7 +48,7 @@ namespace SqlSugar
|
||||
Array.ForEach(entity.Columns.ToArray(), p => {
|
||||
if (!p.IsIgnore&& !p.IsOnlyIgnoreInsert)
|
||||
{
|
||||
pList.Add(p.PropertyInfo); dt.Columns.Add(p.PropertyName);
|
||||
pList.Add(p.PropertyInfo); dt.Columns.Add(p.DbColumnName);
|
||||
}
|
||||
});
|
||||
DataRow row = null;
|
||||
@@ -66,13 +66,13 @@ namespace SqlSugar
|
||||
});
|
||||
dt.Rows.Add(row);
|
||||
}
|
||||
var dllPath = AppDomain.CurrentDomain.BaseDirectory + "failFiles";
|
||||
var dllPath =Path.Combine(AppDomain.CurrentDomain.BaseDirectory , "failFiles");
|
||||
DirectoryInfo dir = new DirectoryInfo(dllPath);
|
||||
if (!dir.Exists)
|
||||
{
|
||||
dir.Create();
|
||||
}
|
||||
var fileName = dllPath + "\\" + Guid.NewGuid().ToString() + ".csv";
|
||||
var fileName =Path.Combine( dllPath , Guid.NewGuid().ToString() + ".csv");
|
||||
var dataTableToCsv = DataTableToCsvString(dt);
|
||||
File.WriteAllText(fileName, dataTableToCsv, new UTF8Encoding(false));
|
||||
MySqlConnection conn = this.Context.Ado.Connection as MySqlConnection;
|
||||
|
@@ -18,7 +18,14 @@ namespace SqlSugar
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
var parameter2 = model.Args[1];
|
||||
return string.Format(" {0}({1}) ", parameter2.MemberValue, parameter.MemberName);
|
||||
if (parameter.MemberName != null && parameter.MemberName is DateTime)
|
||||
{
|
||||
return string.Format(" {0}('{1}') ", parameter2.MemberValue, parameter.MemberName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Format(" {0}({1}) ", parameter2.MemberValue, parameter.MemberName);
|
||||
}
|
||||
}
|
||||
|
||||
public override string Contains(MethodCallExpressionModel model)
|
||||
|
@@ -32,6 +32,9 @@ namespace SqlSugar
|
||||
}
|
||||
public override string GetTranslationColumnName(string columnName)
|
||||
{
|
||||
if (columnName.Contains(":"))
|
||||
return base.GetTranslationColumnName(columnName);
|
||||
else
|
||||
return base.GetTranslationColumnName(columnName).ToUpper();
|
||||
}
|
||||
public override string GetDbColumnName(string entityName, string propertyName)
|
||||
|
@@ -144,6 +144,7 @@ namespace SqlSugar
|
||||
{ typeof(byte[]),NpgsqlDbType.Bytea},
|
||||
{ typeof(bool[]),NpgsqlDbType.Boolean},
|
||||
{typeof(DateTime[]),NpgsqlDbType.Date},
|
||||
{typeof(float[]),NpgsqlDbType.Real},
|
||||
|
||||
|
||||
{ typeof(int?[]),NpgsqlDbType.Integer},
|
||||
@@ -157,6 +158,7 @@ namespace SqlSugar
|
||||
|
||||
|
||||
{ typeof(string[]), NpgsqlDbType.Text},
|
||||
{typeof(float?[]),NpgsqlDbType.Real},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -8,5 +8,59 @@ namespace SqlSugar
|
||||
{
|
||||
public class SqlServerInsertBuilder:InsertBuilder
|
||||
{
|
||||
public override string ToSqlString()
|
||||
{
|
||||
if (IsNoInsertNull)
|
||||
{
|
||||
DbColumnInfoList = DbColumnInfoList.Where(it => it.Value != null).ToList();
|
||||
}
|
||||
var groupList = DbColumnInfoList.GroupBy(it => it.TableId).ToList();
|
||||
var isSingle = groupList.Count() == 1;
|
||||
string columnsString = string.Join(",", groupList.First().Select(it => Builder.GetTranslationColumnName(it.DbColumnName)));
|
||||
if (isSingle)
|
||||
{
|
||||
string columnParametersString = string.Join(",", this.DbColumnInfoList.Select(it => Builder.SqlParameterKeyWord + it.DbColumnName));
|
||||
return string.Format(SqlTemplate, GetTableNameString, columnsString, columnParametersString);
|
||||
}
|
||||
else
|
||||
{
|
||||
StringBuilder batchInsetrSql = new StringBuilder();
|
||||
int pageSize = 200;
|
||||
if (this.EntityInfo.Columns.Count > 30)
|
||||
{
|
||||
pageSize = 50;
|
||||
}
|
||||
else if (this.EntityInfo.Columns.Count > 20)
|
||||
{
|
||||
pageSize = 100;
|
||||
}
|
||||
int pageIndex = 1;
|
||||
int totalRecord = groupList.Count;
|
||||
int pageCount = (totalRecord + pageSize - 1) / pageSize;
|
||||
while (pageCount >= pageIndex)
|
||||
{
|
||||
batchInsetrSql.AppendFormat(SqlTemplateBatch, GetTableNameString, columnsString);
|
||||
int i = 0;
|
||||
foreach (var columns in groupList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList())
|
||||
{
|
||||
var isFirst = i == 0;
|
||||
if (!isFirst)
|
||||
{
|
||||
batchInsetrSql.Append(SqlTemplateBatchUnion);
|
||||
}
|
||||
batchInsetrSql.Append("\r\n SELECT " + string.Join(",", columns.Select(it => string.Format(SqlTemplateBatchSelect, FormatValue(it.Value), Builder.GetTranslationColumnName(it.DbColumnName)))));
|
||||
++i;
|
||||
}
|
||||
pageIndex++;
|
||||
batchInsetrSql.Append("\r\n;\r\n");
|
||||
}
|
||||
var result = batchInsetrSql.ToString();
|
||||
if (this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer)
|
||||
{
|
||||
result += "select SCOPE_IDENTITY();";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,16 +2,17 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
|
||||
public partial class SimpleClient<T> : ISimpleClient<T> where T : class, new()
|
||||
public partial class SimpleClient<T> : ISugarRepository,ISimpleClient<T> where T : class, new()
|
||||
{
|
||||
#region Interface
|
||||
protected ISqlSugarClient Context { get; set; }
|
||||
public ISqlSugarClient Context { get; set; }
|
||||
|
||||
public ITenant AsTenant()
|
||||
{
|
||||
@@ -34,6 +35,17 @@ namespace SqlSugar
|
||||
{
|
||||
return this.Context.GetSimpleClient<ChangeType>();
|
||||
}
|
||||
public RepositoryType ChangeRepository<RepositoryType>() where RepositoryType : ISugarRepository
|
||||
{
|
||||
Type type = typeof(RepositoryType);
|
||||
object o = Activator.CreateInstance(type,new string[]{ null});
|
||||
var result= (RepositoryType)o;
|
||||
if (result.Context == null)
|
||||
{
|
||||
result.Context = this.Context;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public ISugarQueryable<T> AsQueryable()
|
||||
{
|
||||
return Context.Queryable<T>();
|
||||
@@ -292,130 +304,8 @@ namespace SqlSugar
|
||||
public ISqlSugarClient FullClient { get { return this.Context; } }
|
||||
}
|
||||
|
||||
|
||||
[Obsolete("Use SimpleClient<T>")]
|
||||
public partial class SimpleClient
|
||||
public interface ISugarRepository
|
||||
{
|
||||
protected ISqlSugarClient Context { get; set; }
|
||||
public ITenant AsTenant()
|
||||
{
|
||||
return this.Context as ITenant;
|
||||
}
|
||||
public ISqlSugarClient AsSugarClient()
|
||||
{
|
||||
return this.Context;
|
||||
}
|
||||
|
||||
private SimpleClient()
|
||||
{
|
||||
|
||||
}
|
||||
public SimpleClient(ISqlSugarClient context)
|
||||
{
|
||||
this.Context = context;
|
||||
}
|
||||
|
||||
public T GetById<T>(dynamic id) where T : class, new()
|
||||
{
|
||||
return Context.Queryable<T>().InSingle(id);
|
||||
}
|
||||
public int Count<T>(Expression<Func<T, bool>> whereExpression)
|
||||
{
|
||||
return Context.Queryable<T>().Where(whereExpression).Count();
|
||||
}
|
||||
public List<T> GetList<T>() where T : class, new()
|
||||
{
|
||||
return Context.Queryable<T>().ToList();
|
||||
}
|
||||
public T GetSingle<T>(Expression<Func<T, bool>> whereExpression) where T : class, new()
|
||||
{
|
||||
return Context.Queryable<T>().Single(whereExpression);
|
||||
}
|
||||
public List<T> GetList<T>(Expression<Func<T, bool>> whereExpression) where T : class, new()
|
||||
{
|
||||
return Context.Queryable<T>().Where(whereExpression).ToList();
|
||||
}
|
||||
public List<T> GetPageList<T>(Expression<Func<T, bool>> whereExpression, PageModel page) where T : class, new()
|
||||
{
|
||||
int count = 0;
|
||||
var result = Context.Queryable<T>().Where(whereExpression).ToPageList(page.PageIndex, page.PageSize, ref count);
|
||||
page.PageCount = count;
|
||||
return result;
|
||||
}
|
||||
public List<T> GetPageList<T>(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc) where T : class, new()
|
||||
{
|
||||
int count = 0;
|
||||
var result = Context.Queryable<T>().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToPageList(page.PageIndex, page.PageSize, ref count);
|
||||
page.PageCount = count;
|
||||
return result;
|
||||
}
|
||||
public List<T> GetPageList<T>(List<IConditionalModel> conditionalList, PageModel page) where T : class, new()
|
||||
{
|
||||
int count = 0;
|
||||
var result = Context.Queryable<T>().Where(conditionalList).ToPageList(page.PageIndex, page.PageSize, ref count);
|
||||
page.PageCount = count;
|
||||
return result;
|
||||
}
|
||||
public List<T> GetPageList<T>(List<IConditionalModel> conditionalList, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc) where T : class, new()
|
||||
{
|
||||
int count = 0;
|
||||
var result = Context.Queryable<T>().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(conditionalList).ToPageList(page.PageIndex, page.PageSize, ref count);
|
||||
page.PageCount = count;
|
||||
return result;
|
||||
}
|
||||
public bool IsAny<T>(Expression<Func<T, bool>> whereExpression) where T : class, new()
|
||||
{
|
||||
return Context.Queryable<T>().Where(whereExpression).Any();
|
||||
}
|
||||
public bool Insert<T>(T insertObj) where T : class, new()
|
||||
{
|
||||
return this.Context.Insertable(insertObj).ExecuteCommand() > 0;
|
||||
}
|
||||
public int InsertReturnIdentity<T>(T insertObj) where T : class, new()
|
||||
{
|
||||
return this.Context.Insertable(insertObj).ExecuteReturnIdentity();
|
||||
}
|
||||
public bool InsertRange<T>(T[] insertObjs) where T : class, new()
|
||||
{
|
||||
return this.Context.Insertable(insertObjs).ExecuteCommand() > 0;
|
||||
}
|
||||
public bool InsertRange<T>(List<T> insertObjs) where T : class, new()
|
||||
{
|
||||
return this.Context.Insertable(insertObjs).ExecuteCommand() > 0;
|
||||
}
|
||||
public bool Update<T>(T updateObj) where T : class, new()
|
||||
{
|
||||
return this.Context.Updateable(updateObj).ExecuteCommand() > 0;
|
||||
}
|
||||
public bool UpdateRange<T>(T[] updateObjs) where T : class, new()
|
||||
{
|
||||
return this.Context.Updateable(updateObjs).ExecuteCommand() > 0;
|
||||
}
|
||||
public bool UpdateRange<T>(List<T> updateObjs) where T : class, new()
|
||||
{
|
||||
return this.Context.Updateable(updateObjs).ExecuteCommand() > 0;
|
||||
}
|
||||
public bool Update<T>(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression) where T : class, new()
|
||||
{
|
||||
return this.Context.Updateable<T>(columns).Where(whereExpression).ExecuteCommand() > 0;
|
||||
}
|
||||
public bool Delete<T>(T deleteObj) where T : class, new()
|
||||
{
|
||||
return this.Context.Deleteable<T>().Where(deleteObj).ExecuteCommand() > 0;
|
||||
}
|
||||
public bool Delete<T>(Expression<Func<T, bool>> whereExpression) where T : class, new()
|
||||
{
|
||||
return this.Context.Deleteable<T>().Where(whereExpression).ExecuteCommand() > 0;
|
||||
}
|
||||
public bool DeleteById<T>(dynamic id) where T : class, new()
|
||||
{
|
||||
return this.Context.Deleteable<T>().In(id).ExecuteCommand() > 0;
|
||||
}
|
||||
public bool DeleteByIds<T>(dynamic[] ids) where T : class, new()
|
||||
{
|
||||
return this.Context.Deleteable<T>().In(ids).ExecuteCommand() > 0;
|
||||
}
|
||||
[Obsolete("Use AsSugarClient()")]
|
||||
public ISqlSugarClient FullClient { get { return this.Context; } }
|
||||
ISqlSugarClient Context { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@ namespace SqlSugar
|
||||
public bool IsSystemTablesConfig => this.Context.IsSystemTablesConfig;
|
||||
public ConnectionConfig CurrentConnectionConfig { get { return _CurrentConnectionConfig; } set { _CurrentConnectionConfig = value; } }
|
||||
public Guid ContextID { get { return this.Context.ContextID; } set { this.Context.ContextID = value; } }
|
||||
|
||||
public ConfigQuery ConfigQuery { get { return this.Context.ConfigQuery; } set { this.Context.ConfigQuery = value; } }
|
||||
|
||||
public MappingTableList MappingTables { get { return _MappingTables; } set { _MappingTables = value; } }
|
||||
public MappingColumnList MappingColumns { get { return _MappingColumns; } set { _MappingColumns = value; } }
|
||||
|
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
internal static class DataTableExtensions
|
||||
{
|
||||
public static DataTable ToPivotTable<T, TColumn, TRow, TData>(
|
||||
this IEnumerable<T> source,
|
||||
Func<T, TColumn> columnSelector,
|
||||
Expression<Func<T, TRow>> rowSelector,
|
||||
Func<IEnumerable<T>, TData> dataSelector)
|
||||
{
|
||||
DataTable table = new DataTable();
|
||||
var rowName = ((MemberExpression)rowSelector.Body).Member.Name;
|
||||
table.Columns.Add(new DataColumn(rowName));
|
||||
var columns = source.Select(columnSelector).Distinct();
|
||||
|
||||
foreach (var column in columns)
|
||||
table.Columns.Add(new DataColumn(column.ToString()));
|
||||
|
||||
var rows = source.GroupBy(rowSelector.Compile())
|
||||
.Select(rowGroup => new
|
||||
{
|
||||
Key = rowGroup.Key,
|
||||
Values = columns.GroupJoin(
|
||||
rowGroup,
|
||||
c => c,
|
||||
r => columnSelector(r),
|
||||
(c, columnGroup) => dataSelector(columnGroup))
|
||||
});
|
||||
|
||||
foreach (var row in rows)
|
||||
{
|
||||
var dataRow = table.NewRow();
|
||||
var items = row.Values.Cast<object>().ToList();
|
||||
items.Insert(0, row.Key);
|
||||
dataRow.ItemArray = items.ToArray();
|
||||
table.Rows.Add(dataRow);
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
public static List<dynamic> ToPivotList<T, TColumn, TRow, TData>(
|
||||
this IEnumerable<T> source,
|
||||
Func<T, TColumn> columnSelector,
|
||||
Expression<Func<T, TRow>> rowSelector,
|
||||
Func<IEnumerable<T>, TData> dataSelector)
|
||||
{
|
||||
|
||||
var arr = new List<object>();
|
||||
var cols = new List<string>();
|
||||
String rowName = ((MemberExpression)rowSelector.Body).Member.Name;
|
||||
var columns = source.Select(columnSelector).Distinct();
|
||||
|
||||
cols = (new[] { rowName }).Concat(columns.Select(x => x.ToString())).ToList();
|
||||
|
||||
|
||||
var rows = source.GroupBy(rowSelector.Compile())
|
||||
.Select(rowGroup => new
|
||||
{
|
||||
Key = rowGroup.Key,
|
||||
Values = columns.GroupJoin(
|
||||
rowGroup,
|
||||
c => c,
|
||||
r => columnSelector(r),
|
||||
(c, columnGroup) => dataSelector(columnGroup))
|
||||
}).ToList();
|
||||
|
||||
|
||||
foreach (var row in rows)
|
||||
{
|
||||
var items = row.Values.Cast<object>().ToList();
|
||||
items.Insert(0, row.Key);
|
||||
var obj = GetAnonymousObject(cols, items);
|
||||
arr.Add(obj);
|
||||
}
|
||||
return arr.ToList();
|
||||
}
|
||||
private static dynamic GetAnonymousObject(IEnumerable<string> columns, IEnumerable<object> values)
|
||||
{
|
||||
IDictionary<string, object> eo = new ExpandoObject() as IDictionary<string, object>;
|
||||
int i;
|
||||
for (i = 0; i < columns.Count(); i++)
|
||||
{
|
||||
eo.Add(columns.ElementAt<string>(i), values.ElementAt<object>(i));
|
||||
}
|
||||
return eo;
|
||||
}
|
||||
}
|
||||
}
|
@@ -134,6 +134,7 @@ namespace SqlSugar
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@"\+{0} ", "\\" + itemParameter.ParameterName), "+" + newName +" ", RegexOptions.IgnoreCase);
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@" {0}\+", "\\" + itemParameter.ParameterName)," "+ newName + "+", RegexOptions.IgnoreCase);
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@"\|\|{0}\|\|", "\\" + itemParameter.ParameterName), "+" + newName + "+", RegexOptions.IgnoreCase);
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@"\={0}\+", "\\" + itemParameter.ParameterName), "=" + newName + "+", RegexOptions.IgnoreCase);
|
||||
return itemSql;
|
||||
}
|
||||
internal static Type GetRootBaseType(Type entityType)
|
||||
@@ -338,8 +339,17 @@ namespace SqlSugar
|
||||
List<object> methodParameters = new List<object>();
|
||||
foreach (var callItem in callExpresion.Arguments)
|
||||
{
|
||||
var parameter = callItem.GetType().GetProperties().First(it => it.Name == "Value").GetValue(callItem, null);
|
||||
methodParameters.Add(parameter);
|
||||
var parameter = callItem.GetType().GetProperties().FirstOrDefault(it => it.Name == "Value");
|
||||
if (parameter == null)
|
||||
{
|
||||
var value = LambdaExpression.Lambda(callItem).Compile().DynamicInvoke();
|
||||
methodParameters.Add(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
var value = parameter.GetValue(callItem, null);
|
||||
methodParameters.Add(value);
|
||||
}
|
||||
}
|
||||
methodInfo.Invoke(item, methodParameters.ToArray());
|
||||
}
|
||||
|
Reference in New Issue
Block a user