mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-09 15:17:57 +08:00
Update Core
This commit is contained in:
parent
95ff147649
commit
168a46db5d
@ -37,7 +37,7 @@ namespace SqlSugar
|
|||||||
private static readonly MethodInfo getInt32 = typeof(IDataRecord).GetMethod("GetInt32", new Type[] { typeof(int) });
|
private static readonly MethodInfo getInt32 = typeof(IDataRecord).GetMethod("GetInt32", new Type[] { typeof(int) });
|
||||||
private static readonly MethodInfo getInt64 = typeof(IDataRecord).GetMethod("GetInt64", new Type[] { typeof(int) });
|
private static readonly MethodInfo getInt64 = typeof(IDataRecord).GetMethod("GetInt64", new Type[] { typeof(int) });
|
||||||
private static readonly MethodInfo getString = typeof(IDataRecord).GetMethod("GetString", new Type[] { typeof(int) });
|
private static readonly MethodInfo getString = typeof(IDataRecord).GetMethod("GetString", new Type[] { typeof(int) });
|
||||||
private static readonly MethodInfo getConvertValueMethod = typeof(IDataRecordExtensions).GetMethod("GetConvertValue");
|
//private static readonly MethodInfo getConvertValueMethod = typeof(IDataRecordExtensions).GetMethod("GetConvertValue");
|
||||||
private static readonly MethodInfo getdatetimeoffset = typeof(IDataRecordExtensions).GetMethod("Getdatetimeoffset");
|
private static readonly MethodInfo getdatetimeoffset = typeof(IDataRecordExtensions).GetMethod("Getdatetimeoffset");
|
||||||
private static readonly MethodInfo getdatetimeoffsetDate = typeof(IDataRecordExtensions).GetMethod("GetdatetimeoffsetDate");
|
private static readonly MethodInfo getdatetimeoffsetDate = typeof(IDataRecordExtensions).GetMethod("GetdatetimeoffsetDate");
|
||||||
private static readonly MethodInfo getStringGuid = typeof(IDataRecordExtensions).GetMethod("GetStringGuid");
|
private static readonly MethodInfo getStringGuid = typeof(IDataRecordExtensions).GetMethod("GetStringGuid");
|
||||||
@ -223,7 +223,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
else if (bindPropertyType == UtilConstants.StringType&&dbTypeName?.ToLower()== "timestamp")
|
else if (bindPropertyType == UtilConstants.StringType&&dbTypeName?.ToLower()== "timestamp")
|
||||||
{
|
{
|
||||||
method = getConvertValueMethod.MakeGenericMethod(columnInfo.PropertyInfo.PropertyType); ;
|
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
|
||||||
}
|
}
|
||||||
else if (bindPropertyType == UtilConstants.StringType)
|
else if (bindPropertyType == UtilConstants.StringType)
|
||||||
{
|
{
|
||||||
@ -231,7 +231,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
method = getConvertValueMethod.MakeGenericMethod(columnInfo.PropertyInfo.PropertyType);
|
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method.IsVirtual)
|
if (method.IsVirtual)
|
||||||
@ -301,11 +301,11 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
if (bindPropertyType == UtilConstants.DecType)
|
if (bindPropertyType == UtilConstants.DecType)
|
||||||
{
|
{
|
||||||
method = getConvertValueMethod.MakeGenericMethod(bindPropertyType);
|
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
|
||||||
}
|
}
|
||||||
if (bindPropertyType == UtilConstants.IntType)
|
if (bindPropertyType == UtilConstants.IntType)
|
||||||
{
|
{
|
||||||
method = getConvertValueMethod.MakeGenericMethod(bindPropertyType);
|
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CSharpDataType.Guid:
|
case CSharpDataType.Guid:
|
||||||
@ -337,7 +337,7 @@ namespace SqlSugar
|
|||||||
case CSharpDataType.Single:
|
case CSharpDataType.Single:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
method = getConvertValueMethod.MakeGenericMethod(bindPropertyType);
|
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (method == null && bindPropertyType == UtilConstants.StringType)
|
if (method == null && bindPropertyType == UtilConstants.StringType)
|
||||||
@ -346,7 +346,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
if (bindPropertyType == UtilConstants.ObjType)
|
if (bindPropertyType == UtilConstants.ObjType)
|
||||||
{
|
{
|
||||||
method = getConvertValueMethod.MakeGenericMethod(bindPropertyType);
|
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
|
||||||
}
|
}
|
||||||
if (method == null)
|
if (method == null)
|
||||||
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
|
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
|
||||||
|
@ -136,38 +136,22 @@ namespace SqlSugar
|
|||||||
var result = dr.GetInt32(i);
|
var result = dr.GetInt32(i);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
public static T GetConvertValue<T>(this IDataRecord dr, int i)
|
//public static T GetConvertValue<T>(this IDataRecord dr, int i)
|
||||||
{
|
//{
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
if (dr.IsDBNull(i))
|
// if (dr.IsDBNull(i))
|
||||||
{
|
// {
|
||||||
return default(T);
|
// return default(T);
|
||||||
}
|
// }
|
||||||
var result = dr.GetValue(i);
|
// var result = dr.GetValue(i);
|
||||||
return UtilMethods.To<T>(result);
|
// return UtilMethods.To<T>(result);
|
||||||
}
|
// }
|
||||||
catch (Exception ex)
|
// catch (Exception ex)
|
||||||
{
|
// {
|
||||||
if (dr.GetFieldType(i) == UtilConstants.DateType)
|
// return OtherException<T>(dr, i, ex);
|
||||||
{
|
// }
|
||||||
return UtilMethods.To<T>(dr.GetConvertDouble(i));
|
//}
|
||||||
}
|
|
||||||
if (dr.GetFieldType(i) == UtilConstants.GuidType)
|
|
||||||
{
|
|
||||||
var data = dr.GetString(i);
|
|
||||||
if (data.ToString() == "")
|
|
||||||
{
|
|
||||||
return UtilMethods.To<T>(null);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return UtilMethods.To<T>(Guid.Parse(data.ToString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new Exception(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long? GetConvetInt64(this IDataRecord dr, int i)
|
public static long? GetConvetInt64(this IDataRecord dr, int i)
|
||||||
{
|
{
|
||||||
@ -264,19 +248,25 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var result = dr.GetValue(i);
|
return GetOther<T>(dr,i);
|
||||||
return UtilMethods.To<T>(result);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T GetOther<T>(this IDataReader dr, int i)
|
public static T GetOther<T>(this IDataReader dr, int i)
|
||||||
{
|
{
|
||||||
if (dr.IsDBNull(i))
|
try
|
||||||
{
|
{
|
||||||
return default(T);
|
if (dr.IsDBNull(i))
|
||||||
|
{
|
||||||
|
return default(T);
|
||||||
|
}
|
||||||
|
var result = dr.GetValue(i);
|
||||||
|
return UtilMethods.To<T>(result);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return OtherException<T>(dr, i, ex);
|
||||||
}
|
}
|
||||||
var result = dr.GetValue(i);
|
|
||||||
return UtilMethods.To<T>(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T GetJson<T>(this IDataReader dr, int i)
|
public static T GetJson<T>(this IDataReader dr, int i)
|
||||||
@ -330,6 +320,28 @@ namespace SqlSugar
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static T OtherException<T>(IDataRecord dr, int i, Exception ex)
|
||||||
|
{
|
||||||
|
if (dr.GetFieldType(i) == UtilConstants.DateType)
|
||||||
|
{
|
||||||
|
return UtilMethods.To<T>(dr.GetConvertDouble(i));
|
||||||
|
}
|
||||||
|
if (dr.GetFieldType(i) == UtilConstants.GuidType)
|
||||||
|
{
|
||||||
|
var data = dr.GetString(i);
|
||||||
|
if (data.ToString() == "")
|
||||||
|
{
|
||||||
|
return UtilMethods.To<T>(null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return UtilMethods.To<T>(Guid.Parse(data.ToString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Exception(ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2284,6 +2284,22 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return _Avg<TResult>(expression);
|
return _Avg<TResult>(expression);
|
||||||
}
|
}
|
||||||
|
public Task<TResult> MaxAsync<TResult>(Expression<Func<T, T2, TResult>> expression)
|
||||||
|
{
|
||||||
|
return _MaxAsync<TResult>(expression);
|
||||||
|
}
|
||||||
|
public Task<TResult> MinAsync<TResult>(Expression<Func<T, T2, TResult>> expression)
|
||||||
|
{
|
||||||
|
return _MinAsync<TResult>(expression);
|
||||||
|
}
|
||||||
|
public Task<TResult> SumAsync<TResult>(Expression<Func<T, T2, TResult>> expression)
|
||||||
|
{
|
||||||
|
return _SumAsync<TResult>(expression);
|
||||||
|
}
|
||||||
|
public Task<TResult> AvgAsync<TResult>(Expression<Func<T, T2, TResult>> expression)
|
||||||
|
{
|
||||||
|
return _AvgAsync<TResult>(expression);
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region In
|
#region In
|
||||||
@ -2630,6 +2646,22 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return _Avg<TResult>(expression);
|
return _Avg<TResult>(expression);
|
||||||
}
|
}
|
||||||
|
public Task<TResult> MaxAsync<TResult>(Expression<Func<T, T2,T3, TResult>> expression)
|
||||||
|
{
|
||||||
|
return _MaxAsync<TResult>(expression);
|
||||||
|
}
|
||||||
|
public Task<TResult> MinAsync<TResult>(Expression<Func<T, T2,T3, TResult>> expression)
|
||||||
|
{
|
||||||
|
return _MinAsync<TResult>(expression);
|
||||||
|
}
|
||||||
|
public Task<TResult> SumAsync<TResult>(Expression<Func<T, T2,T3, TResult>> expression)
|
||||||
|
{
|
||||||
|
return _SumAsync<TResult>(expression);
|
||||||
|
}
|
||||||
|
public Task<TResult> AvgAsync<TResult>(Expression<Func<T, T2,T3, TResult>> expression)
|
||||||
|
{
|
||||||
|
return _AvgAsync<TResult>(expression);
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region In
|
#region In
|
||||||
|
@ -143,6 +143,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
parameterName = parameterName.Replace("]", "_");
|
parameterName = parameterName.Replace("]", "_");
|
||||||
}
|
}
|
||||||
|
if (parameterName.Contains(this.SqlTranslationLeft))
|
||||||
|
{
|
||||||
|
parameterName = parameterName.Replace(this.SqlTranslationLeft, "_");
|
||||||
|
}
|
||||||
switch (item.ConditionalType)
|
switch (item.ConditionalType)
|
||||||
{
|
{
|
||||||
case ConditionalType.Equal:
|
case ConditionalType.Equal:
|
||||||
@ -198,7 +202,7 @@ namespace SqlSugar
|
|||||||
parameters.Add(new SugarParameter(parameterName, item.FieldValue));
|
parameters.Add(new SugarParameter(parameterName, item.FieldValue));
|
||||||
break;
|
break;
|
||||||
case ConditionalType.IsNullOrEmpty:
|
case ConditionalType.IsNullOrEmpty:
|
||||||
builder.AppendFormat("{0} ({1}) OR ({2}) ", type, item.FieldName.ToSqlFilter() + " IS NULL ", item.FieldName.ToSqlFilter() + " = '' ");
|
builder.AppendFormat(" {0} (({1}) OR ({2})) ", type, item.FieldName.ToSqlFilter() + " IS NULL ", item.FieldName.ToSqlFilter() + " = '' ");
|
||||||
parameters.Add(new SugarParameter(parameterName, item.FieldValue));
|
parameters.Add(new SugarParameter(parameterName, item.FieldValue));
|
||||||
break;
|
break;
|
||||||
case ConditionalType.IsNot:
|
case ConditionalType.IsNot:
|
||||||
|
@ -747,6 +747,10 @@ namespace SqlSugar
|
|||||||
result.Builder = sqlBuilder;
|
result.Builder = sqlBuilder;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
public IStorageable<T> Storageable<T>(T data) where T : class, new()
|
||||||
|
{
|
||||||
|
return Storageable(new List<T>() { data });
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region DbFirst
|
#region DbFirst
|
||||||
|
@ -172,9 +172,11 @@ namespace SqlSugar
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Update by object
|
||||||
|
|
||||||
public IUpdateable<T> WhereColumns(Expression<Func<T, object>> columns)
|
public IUpdateable<T> WhereColumns(Expression<Func<T, object>> columns)
|
||||||
{
|
{
|
||||||
|
ThrowUpdateByExpression();
|
||||||
this.IsWhereColumns = true;
|
this.IsWhereColumns = true;
|
||||||
UpdateBuilder.IsWhereColumns = true;
|
UpdateBuilder.IsWhereColumns = true;
|
||||||
Check.Exception(UpdateParameterIsNull == true, "Updateable<T>().Updateable is error,Use Updateable(obj).WhereColumns");
|
Check.Exception(UpdateParameterIsNull == true, "Updateable<T>().Updateable is error,Use Updateable(obj).WhereColumns");
|
||||||
@ -188,12 +190,15 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public IUpdateable<T> WhereColumns(string columnName)
|
public IUpdateable<T> WhereColumns(string columnName)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ThrowUpdateByExpression();
|
||||||
if (this.WhereColumnList == null) this.WhereColumnList = new List<string>();
|
if (this.WhereColumnList == null) this.WhereColumnList = new List<string>();
|
||||||
this.WhereColumnList.Add(columnName);
|
this.WhereColumnList.Add(columnName);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public IUpdateable<T> WhereColumns(string[] columnNames)
|
public IUpdateable<T> WhereColumns(string[] columnNames)
|
||||||
{
|
{
|
||||||
|
ThrowUpdateByExpression();
|
||||||
if (this.WhereColumnList == null) this.WhereColumnList = new List<string>();
|
if (this.WhereColumnList == null) this.WhereColumnList = new List<string>();
|
||||||
foreach (var columnName in columnNames)
|
foreach (var columnName in columnNames)
|
||||||
{
|
{
|
||||||
@ -202,9 +207,9 @@ namespace SqlSugar
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IUpdateable<T> UpdateColumns(Expression<Func<T, object>> columns)
|
public IUpdateable<T> UpdateColumns(Expression<Func<T, object>> columns)
|
||||||
{
|
{
|
||||||
|
ThrowUpdateByExpression();
|
||||||
var updateColumns = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.ArraySingle).GetResultArray().Select(it => this.SqlBuilder.GetNoTranslationColumnName(it)).ToList();
|
var updateColumns = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.ArraySingle).GetResultArray().Select(it => this.SqlBuilder.GetNoTranslationColumnName(it)).ToList();
|
||||||
List<string> primaryKeys = GetPrimaryKeys();
|
List<string> primaryKeys = GetPrimaryKeys();
|
||||||
foreach (var item in this.UpdateBuilder.DbColumnInfoList)
|
foreach (var item in this.UpdateBuilder.DbColumnInfoList)
|
||||||
@ -220,12 +225,30 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public IUpdateable<T> UpdateColumns(string[] columns)
|
public IUpdateable<T> UpdateColumns(string[] columns)
|
||||||
{
|
{
|
||||||
|
ThrowUpdateByExpression();
|
||||||
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => GetPrimaryKeys().Select(iit => iit.ToLower()).Contains(it.DbColumnName.ToLower()) || columns.Contains(it.PropertyName, StringComparer.OrdinalIgnoreCase)).ToList();
|
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => GetPrimaryKeys().Select(iit => iit.ToLower()).Contains(it.DbColumnName.ToLower()) || columns.Contains(it.PropertyName, StringComparer.OrdinalIgnoreCase)).ToList();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns, Expression<Func<T, object>> columns)
|
||||||
|
{
|
||||||
|
ThrowUpdateByExpression();
|
||||||
|
if (isUpdateColumns)
|
||||||
|
UpdateColumns(columns);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns, string[] columns)
|
||||||
|
{
|
||||||
|
ThrowUpdateByExpression();
|
||||||
|
if (isUpdateColumns)
|
||||||
|
UpdateColumns(columns);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Update by expression
|
||||||
public IUpdateable<T> SetColumns(Expression<Func<T, T>> columns)
|
public IUpdateable<T> SetColumns(Expression<Func<T, T>> columns)
|
||||||
{
|
{
|
||||||
|
ThrowUpdateByObject();
|
||||||
var expResult = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.Update);
|
var expResult = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.Update);
|
||||||
var resultArray = expResult.GetResultArray();
|
var resultArray = expResult.GetResultArray();
|
||||||
Check.ArgumentNullException(resultArray, "UpdateColumns Parameter error, UpdateColumns(it=>new T{ it.id=1}) is valid, UpdateColumns(it=>T) is error");
|
Check.ArgumentNullException(resultArray, "UpdateColumns Parameter error, UpdateColumns(it=>new T{ it.id=1}) is valid, UpdateColumns(it=>T) is error");
|
||||||
@ -247,9 +270,9 @@ namespace SqlSugar
|
|||||||
AppendSets();
|
AppendSets();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IUpdateable<T> SetColumns(Expression<Func<T, bool>> columns)
|
public IUpdateable<T> SetColumns(Expression<Func<T, bool>> columns)
|
||||||
{
|
{
|
||||||
|
ThrowUpdateByObject();
|
||||||
CheckTranscodeing();
|
CheckTranscodeing();
|
||||||
var binaryExp = columns.Body as BinaryExpression;
|
var binaryExp = columns.Body as BinaryExpression;
|
||||||
Check.Exception(!binaryExp.NodeType.IsIn(ExpressionType.Equal), "No support {0}", columns.ToString());
|
Check.Exception(!binaryExp.NodeType.IsIn(ExpressionType.Equal), "No support {0}", columns.ToString());
|
||||||
@ -262,37 +285,24 @@ namespace SqlSugar
|
|||||||
AppendSets();
|
AppendSets();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns, Expression<Func<T, object>> columns)
|
|
||||||
{
|
|
||||||
if (isUpdateColumns)
|
|
||||||
UpdateColumns(columns);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
public IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns, string[] columns)
|
|
||||||
{
|
|
||||||
if (isUpdateColumns)
|
|
||||||
UpdateColumns(columns);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public IUpdateable<T> SetColumnsIF(bool isUpdateColumns, Expression<Func<T, bool>> columns)
|
public IUpdateable<T> SetColumnsIF(bool isUpdateColumns, Expression<Func<T, bool>> columns)
|
||||||
{
|
{
|
||||||
|
ThrowUpdateByObject();
|
||||||
if (isUpdateColumns)
|
if (isUpdateColumns)
|
||||||
SetColumns(columns);
|
SetColumns(columns);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public IUpdateable<T> SetColumnsIF(bool isUpdateColumns, Expression<Func<T, T>> columns)
|
public IUpdateable<T> SetColumnsIF(bool isUpdateColumns, Expression<Func<T, T>> columns)
|
||||||
{
|
{
|
||||||
|
ThrowUpdateByObject();
|
||||||
if (isUpdateColumns)
|
if (isUpdateColumns)
|
||||||
SetColumns(columns);
|
SetColumns(columns);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IUpdateable<T> Where(Expression<Func<T, bool>> expression)
|
public IUpdateable<T> Where(Expression<Func<T, bool>> expression)
|
||||||
{
|
{
|
||||||
|
ThrowUpdateByObject();
|
||||||
var expResult = UpdateBuilder.GetExpressionValue(expression, ResolveExpressType.WhereSingle);
|
var expResult = UpdateBuilder.GetExpressionValue(expression, ResolveExpressType.WhereSingle);
|
||||||
var whereString = expResult.GetResultString();
|
var whereString = expResult.GetResultString();
|
||||||
if (expression.ToString().Contains("Subqueryable()"))
|
if (expression.ToString().Contains("Subqueryable()"))
|
||||||
@ -304,6 +314,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public IUpdateable<T> Where(string whereSql, object parameters = null)
|
public IUpdateable<T> Where(string whereSql, object parameters = null)
|
||||||
{
|
{
|
||||||
|
ThrowUpdateByObject();
|
||||||
if (whereSql.HasValue())
|
if (whereSql.HasValue())
|
||||||
{
|
{
|
||||||
UpdateBuilder.WhereValues.Add(whereSql);
|
UpdateBuilder.WhereValues.Add(whereSql);
|
||||||
@ -316,14 +327,14 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public IUpdateable<T> Where(string fieldName, string conditionalType, object fieldValue)
|
public IUpdateable<T> Where(string fieldName, string conditionalType, object fieldValue)
|
||||||
{
|
{
|
||||||
|
ThrowUpdateByObject();
|
||||||
var whereSql = this.SqlBuilder.GetWhere(fieldName, conditionalType, 0);
|
var whereSql = this.SqlBuilder.GetWhere(fieldName, conditionalType, 0);
|
||||||
this.Where(whereSql);
|
this.Where(whereSql);
|
||||||
string parameterName = this.SqlBuilder.SqlParameterKeyWord + fieldName + "0";
|
string parameterName = this.SqlBuilder.SqlParameterKeyWord + fieldName + "0";
|
||||||
this.UpdateBuilder.Parameters.Add(new SugarParameter(parameterName, fieldValue));
|
this.UpdateBuilder.Parameters.Add(new SugarParameter(parameterName, fieldValue));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Helper
|
#region Helper
|
||||||
private void AppendSets()
|
private void AppendSets()
|
||||||
@ -706,6 +717,15 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ThrowUpdateByExpression()
|
||||||
|
{
|
||||||
|
Check.Exception(UpdateParameterIsNull == true, ErrorMessage.GetThrowMessage("no support SetColumns and Where ", "根据对象进行更新 db.Updateable(现有集合对象) 禁止使用 SetColumns和Where,你可以使用 WhereColumns UpdateColumns 等。更新分为2种方式 1.根据表达式更新 2.根据实体或者集合更新, 具体用法请查看文档 "));
|
||||||
|
}
|
||||||
|
private void ThrowUpdateByObject()
|
||||||
|
{
|
||||||
|
Check.Exception(UpdateParameterIsNull == false, ErrorMessage.GetThrowMessage("no support UpdateColumns and WhereColumns ", "根据表达式进行更新 禁止使用 UpdateColumns和WhereColumns ,你可以使用SetColumns 和 Where。 更新分为2种方式 1.根据表达式更新 2.根据实体或者集合更新 , 具体用法请查看文档 "));
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -443,5 +443,25 @@ namespace SqlSugar
|
|||||||
var parameter2 = model.Args[1];
|
var parameter2 = model.Args[1];
|
||||||
return string.Format(" ({0} | {1}) ", parameter.MemberName, parameter2.MemberName); ;
|
return string.Format(" ({0} | {1}) ", parameter.MemberName, parameter2.MemberName); ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Oracle_ToDate(MethodCallExpressionModel model)
|
||||||
|
{
|
||||||
|
var parameter = model.Args[0];
|
||||||
|
var parameter2 = model.Args[1];
|
||||||
|
return string.Format(" to_date({0},{1}) ", parameter.MemberName, parameter2.MemberName); ;
|
||||||
|
}
|
||||||
|
public string Oracle_ToChar(MethodCallExpressionModel model)
|
||||||
|
{
|
||||||
|
var parameter = model.Args[0];
|
||||||
|
var parameter2 = model.Args[1];
|
||||||
|
return string.Format("to_char({0},{1}) ", parameter.MemberName, parameter2.MemberName); ;
|
||||||
|
}
|
||||||
|
public string SqlServer_DateDiff(MethodCallExpressionModel model)
|
||||||
|
{
|
||||||
|
var parameter = model.Args[0];
|
||||||
|
var parameter2 = model.Args[1];
|
||||||
|
var parameter3 = model.Args[2];
|
||||||
|
return string.Format(" DATEDIFF({0},{1},{2}) ", parameter.MemberValue?.ToString().ToSqlFilter(), parameter2.MemberName, parameter3.MemberName); ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,5 +68,9 @@ namespace SqlSugar
|
|||||||
string CharIndex(MethodCallExpressionModel model);
|
string CharIndex(MethodCallExpressionModel model);
|
||||||
string BitwiseAnd(MethodCallExpressionModel model);
|
string BitwiseAnd(MethodCallExpressionModel model);
|
||||||
string BitwiseInclusiveOR(MethodCallExpressionModel model);
|
string BitwiseInclusiveOR(MethodCallExpressionModel model);
|
||||||
|
|
||||||
|
string Oracle_ToDate(MethodCallExpressionModel model);
|
||||||
|
string Oracle_ToChar(MethodCallExpressionModel model);
|
||||||
|
string SqlServer_DateDiff(MethodCallExpressionModel model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,5 +140,8 @@ namespace SqlSugar
|
|||||||
public static int CharIndex(string findChar,string searchValue) { throw new NotSupportedException("Can only be used in expressions"); }
|
public static int CharIndex(string findChar,string searchValue) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||||
public static int BitwiseAnd(int left, int right) { throw new NotSupportedException("Can only be used in expressions"); }
|
public static int BitwiseAnd(int left, int right) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||||
public static int BitwiseInclusiveOR(int left, int right) { throw new NotSupportedException("Can only be used in expressions"); }
|
public static int BitwiseInclusiveOR(int left, int right) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||||
|
public static DateTime Oracle_ToDate(string date,string format) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||||
|
public static string Oracle_ToChar(DateTime date, string format) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||||
|
public static int SqlServer_DateDiff(string dateType,DateTime date1,DateTime date2) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -680,6 +680,12 @@ namespace SqlSugar
|
|||||||
return this.Context.DbMehtods.BitwiseInclusiveOR(model);
|
return this.Context.DbMehtods.BitwiseInclusiveOR(model);
|
||||||
case "ToDateShort":
|
case "ToDateShort":
|
||||||
return this.Context.DbMehtods.ToDateShort(model);
|
return this.Context.DbMehtods.ToDateShort(model);
|
||||||
|
case "Oracle_ToChar":
|
||||||
|
return this.Context.DbMehtods.Oracle_ToChar(model);
|
||||||
|
case "Oracle_ToDate":
|
||||||
|
return this.Context.DbMehtods.Oracle_ToDate(model);
|
||||||
|
case "SqlServer_DateDiff":
|
||||||
|
return this.Context.DbMehtods.SqlServer_DateDiff(model);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -215,6 +215,10 @@ namespace SqlSugar
|
|||||||
TResult Min<TResult>(Expression<Func<T, T2, TResult>> expression);
|
TResult Min<TResult>(Expression<Func<T, T2, TResult>> expression);
|
||||||
TResult Sum<TResult>(Expression<Func<T, T2, TResult>> expression);
|
TResult Sum<TResult>(Expression<Func<T, T2, TResult>> expression);
|
||||||
TResult Avg<TResult>(Expression<Func<T, T2, TResult>> expression);
|
TResult Avg<TResult>(Expression<Func<T, T2, TResult>> expression);
|
||||||
|
Task<TResult> MaxAsync<TResult>(Expression<Func<T, T2, TResult>> expression);
|
||||||
|
Task<TResult> MinAsync<TResult>(Expression<Func<T, T2, TResult>> expression);
|
||||||
|
Task<TResult> SumAsync<TResult>(Expression<Func<T, T2, TResult>> expression);
|
||||||
|
Task<TResult> AvgAsync<TResult>(Expression<Func<T, T2, TResult>> expression);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region In
|
#region In
|
||||||
@ -302,6 +306,10 @@ namespace SqlSugar
|
|||||||
TResult Min<TResult>(Expression<Func<T, T2, T3, TResult>> expression);
|
TResult Min<TResult>(Expression<Func<T, T2, T3, TResult>> expression);
|
||||||
TResult Sum<TResult>(Expression<Func<T, T2, T3, TResult>> expression);
|
TResult Sum<TResult>(Expression<Func<T, T2, T3, TResult>> expression);
|
||||||
TResult Avg<TResult>(Expression<Func<T, T2, T3, TResult>> expression);
|
TResult Avg<TResult>(Expression<Func<T, T2, T3, TResult>> expression);
|
||||||
|
Task<TResult> MaxAsync<TResult>(Expression<Func<T, T2, T3, TResult>> expression);
|
||||||
|
Task<TResult> MinAsync<TResult>(Expression<Func<T, T2, T3, TResult>> expression);
|
||||||
|
Task<TResult> SumAsync<TResult>(Expression<Func<T, T2, T3, TResult>> expression);
|
||||||
|
Task<TResult> AvgAsync<TResult>(Expression<Func<T, T2, T3, TResult>> expression);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region In
|
#region In
|
||||||
|
@ -117,6 +117,7 @@ namespace SqlSugar
|
|||||||
|
|
||||||
#region Saveable
|
#region Saveable
|
||||||
IStorageable<T> Storageable<T>(List<T> dataList) where T : class, new();
|
IStorageable<T> Storageable<T>(List<T> dataList) where T : class, new();
|
||||||
|
IStorageable<T> Storageable<T>(T data) where T : class, new();
|
||||||
ISaveable<T> Saveable<T>(List<T> saveObjects) where T : class, new();
|
ISaveable<T> Saveable<T>(List<T> saveObjects) where T : class, new();
|
||||||
ISaveable<T> Saveable<T>(T saveObject) where T : class, new();
|
ISaveable<T> Saveable<T>(T saveObject) where T : class, new();
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -18,6 +18,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
if (item.IsIgnore)
|
if (item.IsIgnore)
|
||||||
continue;
|
continue;
|
||||||
|
if (item.PropertyInfo!=null&&UtilMethods.GetUnderType(item.PropertyInfo.PropertyType) == UtilConstants.GuidType && item.Length == 0&&item.DataType==null)
|
||||||
|
{
|
||||||
|
item.Length = Guid.NewGuid().ToString().Length;
|
||||||
|
}
|
||||||
DbColumnInfo dbColumnInfo = this.EntityColumnToDbColumn(entityInfo, tableName, item);
|
DbColumnInfo dbColumnInfo = this.EntityColumnToDbColumn(entityInfo, tableName, item);
|
||||||
columns.Add(dbColumnInfo);
|
columns.Add(dbColumnInfo);
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,6 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
File.Delete(fileName);
|
File.Delete(fileName);
|
||||||
}
|
}
|
||||||
conn.Close();
|
|
||||||
}
|
}
|
||||||
catch (MySqlException ex)
|
catch (MySqlException ex)
|
||||||
{
|
{
|
||||||
@ -99,7 +98,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
this.Context.Ado.Close();
|
CloseDb();
|
||||||
}
|
}
|
||||||
return IsBulkLoad; ;
|
return IsBulkLoad; ;
|
||||||
}
|
}
|
||||||
@ -109,6 +108,15 @@ namespace SqlSugar
|
|||||||
return Task.FromResult(ExecuteBlueCopy());
|
return Task.FromResult(ExecuteBlueCopy());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void CloseDb()
|
||||||
|
{
|
||||||
|
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Context.Ado.Transaction == null)
|
||||||
|
{
|
||||||
|
this.Context.Ado.Connection.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///DataTable to CSV
|
///DataTable to CSV
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -187,7 +187,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return "EXEC sp_dropextendedproperty 'MS_Description','user',dbo,'table','{1}','column',{0}";
|
return "EXEC sp_dropextendedproperty 'MS_Description','user',dbo,'table','{1}','column','{0}'";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
this.Context.Ado.Connection.Close();
|
CloseDb();
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
CloseDb();
|
CloseDb();
|
||||||
@ -57,13 +57,10 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
this.Context.Ado.Connection.Close();
|
CloseDb();
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Context.Ado.Transaction == null)
|
CloseDb();
|
||||||
{
|
|
||||||
this.Context.Ado.Connection.Close();
|
|
||||||
}
|
|
||||||
return DbColumnInfoList.Count;
|
return DbColumnInfoList.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,6 +343,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return this.Context.Storageable(dataList);
|
return this.Context.Storageable(dataList);
|
||||||
}
|
}
|
||||||
|
public IStorageable<T> Storageable<T>(T data) where T : class, new()
|
||||||
|
{
|
||||||
|
return this.Context.Storageable(new List<T> { data});
|
||||||
|
}
|
||||||
public ISaveable<T> Saveable<T>(List<T> saveObjects) where T : class, new()
|
public ISaveable<T> Saveable<T>(List<T> saveObjects) where T : class, new()
|
||||||
{
|
{
|
||||||
return this.Context.Saveable<T>(saveObjects);
|
return this.Context.Saveable<T>(saveObjects);
|
||||||
|
Loading…
Reference in New Issue
Block a user