Add Storageable.WhereColumns(+2)

This commit is contained in:
sunkaixuan 2022-07-09 02:38:48 +08:00
parent 9d896bdc65
commit b1fb0cee94
3 changed files with 26 additions and 2 deletions

View File

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

View File

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

View File

@ -66,6 +66,18 @@ namespace SqlSugar
return thisValue == equalValue; 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) public static string ObjToString(this object thisValue)
{ {
if (thisValue != null) return thisValue.ToString().Trim(); if (thisValue != null) return thisValue.ToString().Trim();