Browse Source

Add Storageable.WhereColumns(+2)

pull/20/head
sunkaixuan 2 years ago
parent
commit
b1fb0cee94
  1. 14
      Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs
  2. 2
      Src/Asp.Net/SqlSugar/Interface/IStorageable.cs
  3. 12
      Src/Asp.Net/SqlSugar/Utilities/UtilConvert.cs

14
Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs

@ -16,6 +16,7 @@ namespace SqlSugar
List<T> dbDataList = new List<T>();
List<KeyValuePair<StorageType, Func<StorageableInfo<T>, bool>, string>> whereFuncs = new List<KeyValuePair<StorageType, Func<StorageableInfo<T>, bool>, string>>();
Expression<Func<T, object>> whereExpression;
Func<DateTime, string> formatTime;
private string asname { get; set; }
public Storageable(List<T> datas, SqlSugarProvider context)
{
@ -261,6 +262,11 @@ namespace SqlSugar
}
}
List<EntityColumnInfo> wherecolumnList;
public IStorageable<T> WhereColumns(Expression<Func<T, object>> columns, Func<DateTime, string> formatTime)
{
this.formatTime = formatTime;
return WhereColumns(columns);
}
public IStorageable<T> WhereColumns(Expression<Func<T, object>> columns)
{
if (columns == null)
@ -300,7 +306,11 @@ namespace SqlSugar
var exp=ExpressionBuilderHelper.CreateNewFields<T>(this.Context.EntityMaintenance.GetEntityInfo<T>(), list);
return this.WhereColumns(exp);
}
public IStorageable<T> WhereColumns(string[] columns, Func<DateTime, string> formatTime)
{
this.formatTime = formatTime;
return WhereColumns(columns);
}
private void SetConditList(List<StorageableInfo<T>> itemList, List<EntityColumnInfo> whereColumns, List<IConditionalModel> conditList)
{
;
@ -331,7 +341,7 @@ namespace SqlSugar
FieldName = item.DbColumnName,
ConditionalType = ConditionalType.Equal,
CSharpTypeName=UtilMethods.GetTypeName(value),
FieldValue = value==null?"null":value.ObjToString(),
FieldValue = value==null?"null":value.ObjToString(formatTime),
FieldValueConvertFunc=this.Context.CurrentConnectionConfig.DbType==DbType.PostgreSQL?
UtilMethods.GetTypeConvert(value):null
}));

2
Src/Asp.Net/SqlSugar/Interface/IStorageable.cs

@ -9,7 +9,9 @@ namespace SqlSugar
public interface IStorageable<T> where T : class, new()
{
IStorageable<T> WhereColumns(Expression<Func<T, object>> columns);
IStorageable<T> WhereColumns(Expression<Func<T, object>> columns,Func<DateTime,string> formatTime);
IStorageable<T> WhereColumns(string [] columns);
IStorageable<T> WhereColumns(string[] columns, Func<DateTime, string> formatTime);
IStorageable<T> SplitInsert(Func<StorageableInfo<T>, bool> conditions, string message=null);
IStorageable<T> SplitUpdate(Func<StorageableInfo<T>, bool> conditions, string message = null);
IStorageable<T> Saveable(string inserMessage = null, string updateMessage = null);

12
Src/Asp.Net/SqlSugar/Utilities/UtilConvert.cs

@ -66,6 +66,18 @@ namespace SqlSugar
return thisValue == equalValue;
}
}
public static string ObjToString(this object thisValue,Func<DateTime,string> formatTime)
{
if (formatTime != null&&thisValue is DateTime)
{
var dt = Convert.ToDateTime(thisValue);
return formatTime(dt);
}
else
{
return thisValue.ObjToString();
}
}
public static string ObjToString(this object thisValue)
{
if (thisValue != null) return thisValue.ToString().Trim();

Loading…
Cancel
Save