mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-23 04:23:47 +08:00
4.5.9.9
This commit is contained in:
@@ -643,7 +643,7 @@ namespace SqlSugar
|
|||||||
var hasParameter = parameters.HasValue();
|
var hasParameter = parameters.HasValue();
|
||||||
if (hasParameter)
|
if (hasParameter)
|
||||||
{
|
{
|
||||||
foreach (var outputParameter in parameters.Where(it => it.Direction == ParameterDirection.Output))
|
foreach (var outputParameter in parameters.Where(it => it.Direction.IsIn(ParameterDirection.Output, ParameterDirection.InputOutput)))
|
||||||
{
|
{
|
||||||
var gobalOutputParamter = this.OutputParameters.Single(it => it.ParameterName == outputParameter.ParameterName);
|
var gobalOutputParamter = this.OutputParameters.Single(it => it.ParameterName == outputParameter.ParameterName);
|
||||||
outputParameter.Value = gobalOutputParamter.Value;
|
outputParameter.Value = gobalOutputParamter.Value;
|
||||||
|
@@ -74,7 +74,7 @@ namespace SqlSugar
|
|||||||
string tableName = this.Context.EntityMaintenance.GetTableName<T>();
|
string tableName = this.Context.EntityMaintenance.GetTableName<T>();
|
||||||
var primaryFields = this.GetPrimaryKeys();
|
var primaryFields = this.GetPrimaryKeys();
|
||||||
var isSinglePrimaryKey = primaryFields.Count == 1;
|
var isSinglePrimaryKey = primaryFields.Count == 1;
|
||||||
Check.ArgumentNullException(primaryFields, string.Format("Table {0} with no primarykey", tableName));
|
Check.Exception(primaryFields.IsNullOrEmpty(), string.Format("Table {0} with no primarykey", tableName));
|
||||||
if (isSinglePrimaryKey)
|
if (isSinglePrimaryKey)
|
||||||
{
|
{
|
||||||
List<object> primaryKeyValues = new List<object>();
|
List<object> primaryKeyValues = new List<object>();
|
||||||
@@ -106,7 +106,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
StringBuilder orString = new StringBuilder();
|
StringBuilder orString = new StringBuilder();
|
||||||
var isFirst = deleteObjs.IndexOf(deleteObj) == 0;
|
var isFirst = deleteObjs.IndexOf(deleteObj) == 0;
|
||||||
if (isFirst)
|
if (!isFirst)
|
||||||
{
|
{
|
||||||
orString.Append(DeleteBuilder.WhereInOrTemplate + UtilConstants.Space);
|
orString.Append(DeleteBuilder.WhereInOrTemplate + UtilConstants.Space);
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ namespace SqlSugar
|
|||||||
StringBuilder andString = new StringBuilder();
|
StringBuilder andString = new StringBuilder();
|
||||||
foreach (var primaryField in primaryFields)
|
foreach (var primaryField in primaryFields)
|
||||||
{
|
{
|
||||||
if (i == 0)
|
if (i != 0)
|
||||||
andString.Append(DeleteBuilder.WhereInAndTemplate + UtilConstants.Space);
|
andString.Append(DeleteBuilder.WhereInAndTemplate + UtilConstants.Space);
|
||||||
var entityPropertyName = this.Context.EntityMaintenance.GetPropertyName<T>(primaryField);
|
var entityPropertyName = this.Context.EntityMaintenance.GetPropertyName<T>(primaryField);
|
||||||
var columnInfo = EntityInfo.Columns.Single(it => it.PropertyName == entityPropertyName);
|
var columnInfo = EntityInfo.Columns.Single(it => it.PropertyName == entityPropertyName);
|
||||||
|
@@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class Expressionable<T> where T : class, new()
|
||||||
|
{
|
||||||
|
Expression<Func<T, bool>> _exp = it=>true;
|
||||||
|
|
||||||
|
public Expressionable<T> And(Expression<Func<T, bool>> exp)
|
||||||
|
{
|
||||||
|
if (_exp == null)
|
||||||
|
_exp = exp;
|
||||||
|
else
|
||||||
|
_exp = Expression.Lambda<Func<T, bool>>(Expression.AndAlso(_exp.Body, exp.Body), _exp.Parameters);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expressionable<T> AndIF(bool isAnd, Expression<Func<T, bool>> exp)
|
||||||
|
{
|
||||||
|
if (isAnd)
|
||||||
|
And(exp);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expressionable<T> Or(Expression<Func<T, bool>> exp)
|
||||||
|
{
|
||||||
|
if (_exp == null)
|
||||||
|
_exp = exp;
|
||||||
|
else
|
||||||
|
_exp = Expression.Lambda<Func<T, bool>>(Expression.OrElse(_exp.Body, exp.Body), _exp.Parameters);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Expressionable<T> OrIF(bool isOr, Expression<Func<T, bool>> exp)
|
||||||
|
{
|
||||||
|
if (isOr)
|
||||||
|
Or(exp);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Expression<Func<T, bool>> ToExpression()
|
||||||
|
{
|
||||||
|
return _exp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Expressionable
|
||||||
|
{
|
||||||
|
public static Expressionable<T> Create<T>() where T : class, new()
|
||||||
|
{
|
||||||
|
return new Expressionable<T>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -437,7 +437,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public virtual ISugarQueryable<T> MergeTable()
|
public virtual ISugarQueryable<T> MergeTable()
|
||||||
{
|
{
|
||||||
Check.Exception(this.QueryBuilder.SelectValue.IsNullOrEmpty(), "MergeTable need to use Select(it=>new{}) Method .");
|
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 ");
|
Check.Exception(this.QueryBuilder.Skip > 0 || this.QueryBuilder.Take > 0 || this.QueryBuilder.OrderByValue.HasValue(), "MergeTable Queryable cannot Take Skip OrderBy PageToList ");
|
||||||
var sql = QueryBuilder.ToSqlString();
|
var sql = QueryBuilder.ToSqlString();
|
||||||
var tableName = this.SqlBuilder.GetPackTable(sql, "MergeTable");
|
var tableName = this.SqlBuilder.GetPackTable(sql, "MergeTable");
|
||||||
|
@@ -65,7 +65,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return "[{0}]=N'{1}'";
|
return Builder.SqlTranslationLeft+"{0}"+Builder.SqlTranslationRight+"=N'{1}'";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public string WhereInAreaTemplate
|
public string WhereInAreaTemplate
|
||||||
|
@@ -25,7 +25,7 @@ namespace SqlSugar
|
|||||||
private bool IsOffIdentity { get; set; }
|
private bool IsOffIdentity { get; set; }
|
||||||
public MappingTableList OldMappingTableList { get; set; }
|
public MappingTableList OldMappingTableList { get; set; }
|
||||||
public bool IsAs { get; set; }
|
public bool IsAs { get; set; }
|
||||||
public int ExecuteCommand()
|
public virtual int ExecuteCommand()
|
||||||
{
|
{
|
||||||
PreToSql();
|
PreToSql();
|
||||||
Check.Exception(UpdateBuilder.WhereValues.IsNullOrEmpty() && GetPrimaryKeys().IsNullOrEmpty(), "You cannot have no primary key and no conditions");
|
Check.Exception(UpdateBuilder.WhereValues.IsNullOrEmpty() && GetPrimaryKeys().IsNullOrEmpty(), "You cannot have no primary key and no conditions");
|
||||||
@@ -52,7 +52,7 @@ namespace SqlSugar
|
|||||||
Task<bool> result = new Task<bool>(() =>
|
Task<bool> result = new Task<bool>(() =>
|
||||||
{
|
{
|
||||||
IUpdateable<T> asyncUpdateable = CopyUpdateable();
|
IUpdateable<T> asyncUpdateable = CopyUpdateable();
|
||||||
return asyncUpdateable.ExecuteCommand()>0;
|
return asyncUpdateable.ExecuteCommand() > 0;
|
||||||
});
|
});
|
||||||
result.Start();
|
result.Start();
|
||||||
return result;
|
return result;
|
||||||
@@ -125,7 +125,19 @@ namespace SqlSugar
|
|||||||
item.IsPrimarykey = true;
|
item.IsPrimarykey = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => updateColumns.Any(uc=>uc.Equals(it.PropertyName,StringComparison.CurrentCultureIgnoreCase)) || it.IsPrimarykey || it.IsIdentity).ToList();
|
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => updateColumns.Any(uc => uc.Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase)) || it.IsPrimarykey || it.IsIdentity).ToList();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IUpdateable<T> UpdateColumns(Expression<Func<T, bool>> columns) {
|
||||||
|
var binaryExp = columns.Body as BinaryExpression;
|
||||||
|
Check.Exception(!binaryExp.NodeType.IsIn(ExpressionType.Equal), "No support {0}", columns.ToString());
|
||||||
|
Check.Exception(!(binaryExp.Left is MemberExpression), "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().Trim().TrimStart('(').TrimEnd(')');
|
||||||
|
string key = SqlBuilder.GetNoTranslationColumnName(expResult);
|
||||||
|
UpdateBuilder.SetValues.Add(new KeyValuePair<string, string>(SqlBuilder.GetTranslationColumnName(key), expResult));
|
||||||
|
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(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();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -57,7 +57,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
ResolveMemberValue(parameter, baseParameter, isLeft, isSetTempData, expression);
|
ResolveMemberValue(parameter, baseParameter, isLeft, isSetTempData, expression);
|
||||||
}
|
}
|
||||||
else if (fieldIsBool)
|
else if (fieldIsBool&& !this.Context.ResolveType.IsIn(ResolveExpressType.FieldSingle, ResolveExpressType.FieldMultiple))
|
||||||
{
|
{
|
||||||
ResolvefieldIsBool(parameter, baseParameter, isLeft, isSetTempData, expression, isSingle);
|
ResolvefieldIsBool(parameter, baseParameter, isLeft, isSetTempData, expression, isSingle);
|
||||||
}
|
}
|
||||||
|
@@ -12,6 +12,8 @@ namespace SqlSugar
|
|||||||
CommandType CommandType { get; set; }
|
CommandType CommandType { get; set; }
|
||||||
String AppendWhereOrAnd(bool isWhere, string sqlString);
|
String AppendWhereOrAnd(bool isWhere, string sqlString);
|
||||||
string AppendHaving(string sqlString);
|
string AppendHaving(string sqlString);
|
||||||
|
string SqlTranslationLeft { get; }
|
||||||
|
string SqlTranslationRight { get; }
|
||||||
SqlQueryBuilder SqlQueryBuilder { get; set; }
|
SqlQueryBuilder SqlQueryBuilder { get; set; }
|
||||||
QueryBuilder QueryBuilder { get; set; }
|
QueryBuilder QueryBuilder { get; set; }
|
||||||
InsertBuilder InsertBuilder { get; set; }
|
InsertBuilder InsertBuilder { get; set; }
|
||||||
|
@@ -25,6 +25,7 @@ namespace SqlSugar
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IUpdateable<T> WhereColumns(Expression<Func<T, object>> columns);
|
IUpdateable<T> WhereColumns(Expression<Func<T, object>> columns);
|
||||||
IUpdateable<T> UpdateColumns(Expression<Func<T, object>> columns);
|
IUpdateable<T> UpdateColumns(Expression<Func<T, object>> columns);
|
||||||
|
IUpdateable<T> UpdateColumns(Expression<Func<T, bool>> columns);
|
||||||
IUpdateable<T> UpdateColumns(Func<string, bool> updateColumMethod);
|
IUpdateable<T> UpdateColumns(Func<string, bool> updateColumMethod);
|
||||||
IUpdateable<T> UpdateColumns(Expression<Func<T, T>> columns);
|
IUpdateable<T> UpdateColumns(Expression<Func<T, T>> columns);
|
||||||
IUpdateable<T> IgnoreColumns(Expression<Func<T, object>> columns);
|
IUpdateable<T> IgnoreColumns(Expression<Func<T, object>> columns);
|
||||||
|
@@ -98,7 +98,7 @@ namespace SqlSugar
|
|||||||
sqlParameter.DbType = parameter.DbType;
|
sqlParameter.DbType = parameter.DbType;
|
||||||
sqlParameter.Direction = parameter.Direction;
|
sqlParameter.Direction = parameter.Direction;
|
||||||
result[index] = sqlParameter;
|
result[index] = sqlParameter;
|
||||||
if (sqlParameter.Direction == ParameterDirection.Output)
|
if (sqlParameter.Direction.IsIn(ParameterDirection.Output, ParameterDirection.InputOutput))
|
||||||
{
|
{
|
||||||
if (this.OutputParameters == null) this.OutputParameters = new List<IDataParameter>();
|
if (this.OutputParameters == null) this.OutputParameters = new List<IDataParameter>();
|
||||||
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName);
|
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName);
|
||||||
|
@@ -9,7 +9,28 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
protected override string TomultipleSqlString(List<IGrouping<int, DbColumnInfo>> groupList)
|
protected override string TomultipleSqlString(List<IGrouping<int, DbColumnInfo>> groupList)
|
||||||
{
|
{
|
||||||
throw new Exception("Batch updates are not supported for the time being. Please wait for updates");
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.AppendLine(string.Join("\r\n", groupList.Select(t =>
|
||||||
|
{
|
||||||
|
var updateTable = string.Format("UPDATE {0} SET", base.GetTableNameStringNoWith);
|
||||||
|
var setValues = string.Join(",", t.Where(s => !s.IsPrimarykey).Select(m => GetOracleUpdateColums(m)).ToArray());
|
||||||
|
var pkList = t.Where(s => s.IsPrimarykey).ToList();
|
||||||
|
List<string> whereList = new List<string>();
|
||||||
|
foreach (var item in pkList)
|
||||||
|
{
|
||||||
|
var isFirst = pkList.First() == item;
|
||||||
|
var whereString = isFirst ? " " : " AND ";
|
||||||
|
whereString += GetOracleUpdateColums(item);
|
||||||
|
whereList.Add(whereString);
|
||||||
|
}
|
||||||
|
return string.Format("{0} {1} WHERE {2};", updateTable, setValues, string.Join("AND", whereList));
|
||||||
|
}).ToArray()));
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetOracleUpdateColums(DbColumnInfo m)
|
||||||
|
{
|
||||||
|
return string.Format("\"{0}\"={1}", m.DbColumnName.ToUpper(), FormatValue(m.Value));
|
||||||
}
|
}
|
||||||
public override object FormatValue(object value)
|
public override object FormatValue(object value)
|
||||||
{
|
{
|
||||||
|
@@ -94,7 +94,8 @@ namespace SqlSugar
|
|||||||
sqlParameter.Value = parameter.Value;
|
sqlParameter.Value = parameter.Value;
|
||||||
sqlParameter.DbType = parameter.DbType;
|
sqlParameter.DbType = parameter.DbType;
|
||||||
result[index] = sqlParameter;
|
result[index] = sqlParameter;
|
||||||
if (sqlParameter.Direction == ParameterDirection.Output) {
|
if (sqlParameter.Direction.IsIn(ParameterDirection.Output, ParameterDirection.InputOutput))
|
||||||
|
{
|
||||||
if (this.OutputParameters == null) this.OutputParameters = new List<IDataParameter>();
|
if (this.OutputParameters == null) this.OutputParameters = new List<IDataParameter>();
|
||||||
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName);
|
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName);
|
||||||
this.OutputParameters.Add(sqlParameter);
|
this.OutputParameters.Add(sqlParameter);
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
<Version>4.5.9.6</Version>
|
<Version>4.5.9.9</Version>
|
||||||
<Copyright>sun_kai_xuan</Copyright>
|
<Copyright>sun_kai_xuan</Copyright>
|
||||||
<PackageProjectUrl>https://github.com/sunkaixuan/SqlSugar</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/sunkaixuan/SqlSugar</PackageProjectUrl>
|
||||||
<PackageLicenseUrl></PackageLicenseUrl>
|
<PackageLicenseUrl></PackageLicenseUrl>
|
||||||
|
Binary file not shown.
Reference in New Issue
Block a user