Browse Source

Add db.Utilities.PageEach

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
c1fd924f2c
  1. 20
      Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs
  2. 1
      Src/Asp.Net/SqlSugar/Interface/IContextMethods.cs

20
Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Dynamic; using System.Dynamic;
@ -460,7 +461,8 @@ namespace SqlSugar
{ {
builder.AppendFormat(" ( "); builder.AppendFormat(" ( ");
}else if (isFirst) }
else if (isFirst)
{ {
builder.AppendFormat(" {0} ( ", con.Key.ToString().ToUpper()); builder.AppendFormat(" {0} ( ", con.Key.ToString().ToUpper());
} }
@ -497,5 +499,21 @@ namespace SqlSugar
return item.FieldValue; return item.FieldValue;
} }
#endregion #endregion
#region
public void PageEach<T>(IEnumerable<T> pageItems,int pageSize, Action<List<T>> action)
{
if (pageItems != null&& pageItems.Any())
{
int totalRecord = pageItems.Count();
int pageCount = (totalRecord + pageSize - 1) / pageSize;
for (int i = 1; i <= pageCount; i++)
{
var list = pageItems.Skip((i - 1) * pageSize).Take(pageSize).ToList();
action(list);
}
}
}
#endregion
} }
} }

1
Src/Asp.Net/SqlSugar/Interface/IContextMethods.cs

@ -25,6 +25,7 @@ namespace SqlSugar
void RemoveCacheAll<T>(); void RemoveCacheAll<T>();
void RemoveCache<T>(string key); void RemoveCache<T>(string key);
KeyValuePair<string, SugarParameter[]> ConditionalModelToSql(List<IConditionalModel> models,int beginIndex=0); KeyValuePair<string, SugarParameter[]> ConditionalModelToSql(List<IConditionalModel> models,int beginIndex=0);
void PageEach<T>(IEnumerable<T> pageItems, int pageSize, Action<List<T>> action);
} }
} }

Loading…
Cancel
Save