mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-22 20:13:41 +08:00
4.5.9.9
This commit is contained in:
@@ -643,7 +643,7 @@ namespace SqlSugar
|
||||
var hasParameter = parameters.HasValue();
|
||||
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);
|
||||
outputParameter.Value = gobalOutputParamter.Value;
|
||||
|
@@ -74,7 +74,7 @@ namespace SqlSugar
|
||||
string tableName = this.Context.EntityMaintenance.GetTableName<T>();
|
||||
var primaryFields = this.GetPrimaryKeys();
|
||||
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)
|
||||
{
|
||||
List<object> primaryKeyValues = new List<object>();
|
||||
@@ -106,7 +106,7 @@ namespace SqlSugar
|
||||
{
|
||||
StringBuilder orString = new StringBuilder();
|
||||
var isFirst = deleteObjs.IndexOf(deleteObj) == 0;
|
||||
if (isFirst)
|
||||
if (!isFirst)
|
||||
{
|
||||
orString.Append(DeleteBuilder.WhereInOrTemplate + UtilConstants.Space);
|
||||
}
|
||||
@@ -114,7 +114,7 @@ namespace SqlSugar
|
||||
StringBuilder andString = new StringBuilder();
|
||||
foreach (var primaryField in primaryFields)
|
||||
{
|
||||
if (i == 0)
|
||||
if (i != 0)
|
||||
andString.Append(DeleteBuilder.WhereInAndTemplate + UtilConstants.Space);
|
||||
var entityPropertyName = this.Context.EntityMaintenance.GetPropertyName<T>(primaryField);
|
||||
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()
|
||||
{
|
||||
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 ");
|
||||
var sql = QueryBuilder.ToSqlString();
|
||||
var tableName = this.SqlBuilder.GetPackTable(sql, "MergeTable");
|
||||
|
@@ -65,7 +65,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
return "[{0}]=N'{1}'";
|
||||
return Builder.SqlTranslationLeft+"{0}"+Builder.SqlTranslationRight+"=N'{1}'";
|
||||
}
|
||||
}
|
||||
public string WhereInAreaTemplate
|
||||
|
@@ -25,7 +25,7 @@ namespace SqlSugar
|
||||
private bool IsOffIdentity { get; set; }
|
||||
public MappingTableList OldMappingTableList { get; set; }
|
||||
public bool IsAs { get; set; }
|
||||
public int ExecuteCommand()
|
||||
public virtual int ExecuteCommand()
|
||||
{
|
||||
PreToSql();
|
||||
Check.Exception(UpdateBuilder.WhereValues.IsNullOrEmpty() && GetPrimaryKeys().IsNullOrEmpty(), "You cannot have no primary key and no conditions");
|
||||
@@ -129,6 +129,18 @@ namespace SqlSugar
|
||||
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;
|
||||
}
|
||||
|
||||
public IUpdateable<T> UpdateColumns(Func<string, bool> updateColumMethod)
|
||||
{
|
||||
List<string> primaryKeys = GetPrimaryKeys();
|
||||
|
@@ -57,7 +57,7 @@ namespace SqlSugar
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@@ -12,6 +12,8 @@ namespace SqlSugar
|
||||
CommandType CommandType { get; set; }
|
||||
String AppendWhereOrAnd(bool isWhere, string sqlString);
|
||||
string AppendHaving(string sqlString);
|
||||
string SqlTranslationLeft { get; }
|
||||
string SqlTranslationRight { get; }
|
||||
SqlQueryBuilder SqlQueryBuilder { get; set; }
|
||||
QueryBuilder QueryBuilder { get; set; }
|
||||
InsertBuilder InsertBuilder { get; set; }
|
||||
|
@@ -25,6 +25,7 @@ namespace SqlSugar
|
||||
/// <returns></returns>
|
||||
IUpdateable<T> WhereColumns(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(Expression<Func<T, T>> columns);
|
||||
IUpdateable<T> IgnoreColumns(Expression<Func<T, object>> columns);
|
||||
|
@@ -98,7 +98,7 @@ namespace SqlSugar
|
||||
sqlParameter.DbType = parameter.DbType;
|
||||
sqlParameter.Direction = parameter.Direction;
|
||||
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>();
|
||||
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName);
|
||||
|
@@ -9,7 +9,28 @@ namespace SqlSugar
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@@ -94,7 +94,8 @@ namespace SqlSugar
|
||||
sqlParameter.Value = parameter.Value;
|
||||
sqlParameter.DbType = parameter.DbType;
|
||||
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>();
|
||||
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName);
|
||||
this.OutputParameters.Add(sqlParameter);
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Version>4.5.9.6</Version>
|
||||
<Version>4.5.9.9</Version>
|
||||
<Copyright>sun_kai_xuan</Copyright>
|
||||
<PackageProjectUrl>https://github.com/sunkaixuan/SqlSugar</PackageProjectUrl>
|
||||
<PackageLicenseUrl></PackageLicenseUrl>
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user