diff --git a/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs b/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs index 4cb37ef1c..a52186376 100644 --- a/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs +++ b/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Data; using System.Dynamic; @@ -144,7 +145,7 @@ namespace SqlSugar if (readerValues.Any(it => it.Key.Equals(name, StringComparison.CurrentCultureIgnoreCase))) { var addValue = readerValues.ContainsKey(name) ? readerValues[name] : readerValues.First(it => it.Key.Equals(name, StringComparison.CurrentCultureIgnoreCase)).Value; - if (addValue == DBNull.Value||addValue==null) + if (addValue == DBNull.Value || addValue == null) { if (item.PropertyType.IsIn(UtilConstants.IntType, UtilConstants.DecType, UtilConstants.DobType, UtilConstants.ByteType)) { @@ -449,24 +450,25 @@ namespace SqlSugar else { var item = model as ConditionalCollections; - if (item != null&& item.ConditionalList.HasValue()) + if (item != null && item.ConditionalList.HasValue()) { foreach (var con in item.ConditionalList) { var index = item.ConditionalList.IndexOf(con); var isFirst = index == 0; var isLast = index == (item.ConditionalList.Count - 1); - if (models.IndexOf(item) == 0 &&index==0&& beginIndex == 0) + if (models.IndexOf(item) == 0 && index == 0 && beginIndex == 0) { builder.AppendFormat(" ( "); - }else if (isFirst) + } + else if (isFirst) { builder.AppendFormat(" {0} ( ", con.Key.ToString().ToUpper()); } List conModels = new List(); conModels.Add(con.Value); - var childSqlInfo = ConditionalModelToSql(conModels, 1000 * (1 + index)+ models.IndexOf(item)); + var childSqlInfo = ConditionalModelToSql(conModels, 1000 * (1 + index) + models.IndexOf(item)); if (!isFirst) { @@ -497,5 +499,21 @@ namespace SqlSugar return item.FieldValue; } #endregion + + #region + public void PageEach(IEnumerable pageItems,int pageSize, Action> 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 } } diff --git a/Src/Asp.Net/SqlSugar/Interface/IContextMethods.cs b/Src/Asp.Net/SqlSugar/Interface/IContextMethods.cs index 2edf45c59..85256c276 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IContextMethods.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IContextMethods.cs @@ -25,6 +25,7 @@ namespace SqlSugar void RemoveCacheAll(); void RemoveCache(string key); KeyValuePair ConditionalModelToSql(List models,int beginIndex=0); + void PageEach(IEnumerable pageItems, int pageSize, Action> action); } }