mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-03 20:27:56 +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 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 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 getdatetimeoffsetDate = typeof(IDataRecordExtensions).GetMethod("GetdatetimeoffsetDate");
|
||||
private static readonly MethodInfo getStringGuid = typeof(IDataRecordExtensions).GetMethod("GetStringGuid");
|
||||
@ -223,7 +223,7 @@ namespace SqlSugar
|
||||
}
|
||||
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)
|
||||
{
|
||||
@ -231,7 +231,7 @@ namespace SqlSugar
|
||||
}
|
||||
else
|
||||
{
|
||||
method = getConvertValueMethod.MakeGenericMethod(columnInfo.PropertyInfo.PropertyType);
|
||||
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
|
||||
}
|
||||
|
||||
if (method.IsVirtual)
|
||||
@ -301,11 +301,11 @@ namespace SqlSugar
|
||||
}
|
||||
if (bindPropertyType == UtilConstants.DecType)
|
||||
{
|
||||
method = getConvertValueMethod.MakeGenericMethod(bindPropertyType);
|
||||
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
|
||||
}
|
||||
if (bindPropertyType == UtilConstants.IntType)
|
||||
{
|
||||
method = getConvertValueMethod.MakeGenericMethod(bindPropertyType);
|
||||
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
|
||||
}
|
||||
break;
|
||||
case CSharpDataType.Guid:
|
||||
@ -337,7 +337,7 @@ namespace SqlSugar
|
||||
case CSharpDataType.Single:
|
||||
break;
|
||||
default:
|
||||
method = getConvertValueMethod.MakeGenericMethod(bindPropertyType);
|
||||
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
|
||||
break;
|
||||
}
|
||||
if (method == null && bindPropertyType == UtilConstants.StringType)
|
||||
@ -346,7 +346,7 @@ namespace SqlSugar
|
||||
}
|
||||
if (bindPropertyType == UtilConstants.ObjType)
|
||||
{
|
||||
method = getConvertValueMethod.MakeGenericMethod(bindPropertyType);
|
||||
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
|
||||
}
|
||||
if (method == null)
|
||||
method = isNullableType ? getOtherNull.MakeGenericMethod(bindPropertyType) : getOther.MakeGenericMethod(bindPropertyType);
|
||||
|
@ -136,38 +136,22 @@ namespace SqlSugar
|
||||
var result = dr.GetInt32(i);
|
||||
return result;
|
||||
}
|
||||
public static T GetConvertValue<T>(this IDataRecord dr, int i)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (dr.IsDBNull(i))
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
var result = dr.GetValue(i);
|
||||
return UtilMethods.To<T>(result);
|
||||
}
|
||||
catch (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);
|
||||
}
|
||||
}
|
||||
//public static T GetConvertValue<T>(this IDataRecord dr, int i)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// 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);
|
||||
// }
|
||||
//}
|
||||
|
||||
public static long? GetConvetInt64(this IDataRecord dr, int i)
|
||||
{
|
||||
@ -264,19 +248,25 @@ namespace SqlSugar
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var result = dr.GetValue(i);
|
||||
return UtilMethods.To<T>(result);
|
||||
return GetOther<T>(dr,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)
|
||||
@ -330,6 +320,28 @@ namespace SqlSugar
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -2284,6 +2284,22 @@ namespace SqlSugar
|
||||
{
|
||||
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
|
||||
|
||||
#region In
|
||||
@ -2630,6 +2646,22 @@ namespace SqlSugar
|
||||
{
|
||||
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
|
||||
|
||||
#region In
|
||||
|
@ -143,6 +143,10 @@ namespace SqlSugar
|
||||
{
|
||||
parameterName = parameterName.Replace("]", "_");
|
||||
}
|
||||
if (parameterName.Contains(this.SqlTranslationLeft))
|
||||
{
|
||||
parameterName = parameterName.Replace(this.SqlTranslationLeft, "_");
|
||||
}
|
||||
switch (item.ConditionalType)
|
||||
{
|
||||
case ConditionalType.Equal:
|
||||
@ -198,7 +202,7 @@ namespace SqlSugar
|
||||
parameters.Add(new SugarParameter(parameterName, item.FieldValue));
|
||||
break;
|
||||
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));
|
||||
break;
|
||||
case ConditionalType.IsNot:
|
||||
|
@ -747,6 +747,10 @@ namespace SqlSugar
|
||||
result.Builder = sqlBuilder;
|
||||
return result;
|
||||
}
|
||||
public IStorageable<T> Storageable<T>(T data) where T : class, new()
|
||||
{
|
||||
return Storageable(new List<T>() { data });
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region DbFirst
|
||||
|
@ -172,9 +172,11 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
#region Update by object
|
||||
|
||||
public IUpdateable<T> WhereColumns(Expression<Func<T, object>> columns)
|
||||
{
|
||||
ThrowUpdateByExpression();
|
||||
this.IsWhereColumns = true;
|
||||
UpdateBuilder.IsWhereColumns = true;
|
||||
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)
|
||||
{
|
||||
|
||||
ThrowUpdateByExpression();
|
||||
if (this.WhereColumnList == null) this.WhereColumnList = new List<string>();
|
||||
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)
|
||||
{
|
||||
@ -202,9 +207,9 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
List<string> primaryKeys = GetPrimaryKeys();
|
||||
foreach (var item in this.UpdateBuilder.DbColumnInfoList)
|
||||
@ -220,12 +225,30 @@ namespace SqlSugar
|
||||
}
|
||||
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();
|
||||
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)
|
||||
{
|
||||
ThrowUpdateByObject();
|
||||
var expResult = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.Update);
|
||||
var resultArray = expResult.GetResultArray();
|
||||
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();
|
||||
return this;
|
||||
}
|
||||
|
||||
public IUpdateable<T> SetColumns(Expression<Func<T, bool>> columns)
|
||||
{
|
||||
ThrowUpdateByObject();
|
||||
CheckTranscodeing();
|
||||
var binaryExp = columns.Body as BinaryExpression;
|
||||
Check.Exception(!binaryExp.NodeType.IsIn(ExpressionType.Equal), "No support {0}", columns.ToString());
|
||||
@ -262,37 +285,24 @@ namespace SqlSugar
|
||||
AppendSets();
|
||||
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)
|
||||
{
|
||||
ThrowUpdateByObject();
|
||||
if (isUpdateColumns)
|
||||
SetColumns(columns);
|
||||
return this;
|
||||
}
|
||||
public IUpdateable<T> SetColumnsIF(bool isUpdateColumns, Expression<Func<T, T>> columns)
|
||||
{
|
||||
ThrowUpdateByObject();
|
||||
if (isUpdateColumns)
|
||||
SetColumns(columns);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public IUpdateable<T> Where(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
ThrowUpdateByObject();
|
||||
var expResult = UpdateBuilder.GetExpressionValue(expression, ResolveExpressType.WhereSingle);
|
||||
var whereString = expResult.GetResultString();
|
||||
if (expression.ToString().Contains("Subqueryable()"))
|
||||
@ -304,6 +314,7 @@ namespace SqlSugar
|
||||
}
|
||||
public IUpdateable<T> Where(string whereSql, object parameters = null)
|
||||
{
|
||||
ThrowUpdateByObject();
|
||||
if (whereSql.HasValue())
|
||||
{
|
||||
UpdateBuilder.WhereValues.Add(whereSql);
|
||||
@ -316,14 +327,14 @@ namespace SqlSugar
|
||||
}
|
||||
public IUpdateable<T> Where(string fieldName, string conditionalType, object fieldValue)
|
||||
{
|
||||
ThrowUpdateByObject();
|
||||
var whereSql = this.SqlBuilder.GetWhere(fieldName, conditionalType, 0);
|
||||
this.Where(whereSql);
|
||||
string parameterName = this.SqlBuilder.SqlParameterKeyWord + fieldName + "0";
|
||||
this.UpdateBuilder.Parameters.Add(new SugarParameter(parameterName, fieldValue));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Helper
|
||||
private void AppendSets()
|
||||
@ -706,6 +717,15 @@ namespace SqlSugar
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -443,5 +443,25 @@ namespace SqlSugar
|
||||
var parameter2 = model.Args[1];
|
||||
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 BitwiseAnd(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 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 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);
|
||||
case "ToDateShort":
|
||||
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:
|
||||
break;
|
||||
}
|
||||
|
@ -215,6 +215,10 @@ namespace SqlSugar
|
||||
TResult Min<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);
|
||||
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
|
||||
|
||||
#region In
|
||||
@ -302,6 +306,10 @@ namespace SqlSugar
|
||||
TResult Min<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);
|
||||
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
|
||||
|
||||
#region In
|
||||
|
@ -117,6 +117,7 @@ namespace SqlSugar
|
||||
|
||||
#region Saveable
|
||||
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>(T saveObject) where T : class, new();
|
||||
#endregion
|
||||
|
@ -18,6 +18,10 @@ namespace SqlSugar
|
||||
{
|
||||
if (item.IsIgnore)
|
||||
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);
|
||||
columns.Add(dbColumnInfo);
|
||||
}
|
||||
|
@ -91,7 +91,6 @@ namespace SqlSugar
|
||||
{
|
||||
File.Delete(fileName);
|
||||
}
|
||||
conn.Close();
|
||||
}
|
||||
catch (MySqlException ex)
|
||||
{
|
||||
@ -99,7 +98,7 @@ namespace SqlSugar
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.Context.Ado.Close();
|
||||
CloseDb();
|
||||
}
|
||||
return IsBulkLoad; ;
|
||||
}
|
||||
@ -109,6 +108,15 @@ namespace SqlSugar
|
||||
return Task.FromResult(ExecuteBlueCopy());
|
||||
}
|
||||
|
||||
|
||||
private void CloseDb()
|
||||
{
|
||||
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Context.Ado.Transaction == null)
|
||||
{
|
||||
this.Context.Ado.Connection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///DataTable to CSV
|
||||
/// </summary>
|
||||
|
@ -187,7 +187,7 @@ namespace SqlSugar
|
||||
{
|
||||
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)
|
||||
{
|
||||
this.Context.Ado.Connection.Close();
|
||||
CloseDb();
|
||||
throw ex;
|
||||
}
|
||||
CloseDb();
|
||||
@ -57,13 +57,10 @@ namespace SqlSugar
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Context.Ado.Connection.Close();
|
||||
CloseDb();
|
||||
throw ex;
|
||||
}
|
||||
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Context.Ado.Transaction == null)
|
||||
{
|
||||
this.Context.Ado.Connection.Close();
|
||||
}
|
||||
CloseDb();
|
||||
return DbColumnInfoList.Count;
|
||||
}
|
||||
|
||||
|
@ -343,6 +343,10 @@ namespace SqlSugar
|
||||
{
|
||||
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()
|
||||
{
|
||||
return this.Context.Saveable<T>(saveObjects);
|
||||
|
Loading…
Reference in New Issue
Block a user