将结果从数据库拆分为& quot;""共10 [英] Split results from DB into "chunks" of 10

查看:92
本文介绍了将结果从数据库拆分为& quot;""共10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午

我需要一只手将1200个结果分成10个块",以便我可以使用Amazon MWS API处理这些结果.谁能提供任何有关我将如何执行此操作的指导?

I need a hand to split over 1200 results into "chunks" of 10 so i can process these results with the Amazon MWS API. Can anyone provide any guidance on how i would go about doing this please?

 List<string> prodASIN = dc.aboProducts.Select(a => a.asin).Take(10).ToList();

我目前有这个,可以用.但是我有1200多个结果,并且需要遍历每10个结果,以便我可以对其进行处理并将其传递给Amazon MWS API

I currently have this, which works. But i have 1200+ results and need to loop through each 10 so i can process them and pass them over to the Amazon MWS API

推荐答案

为什么不尝试以下方法:

Why not try something like:

//Load all the database entries into Memory
List<string> prodASINs = dc.aboProducts.Select(a => a.asin).ToList();
var count = prodASINs.Count();
//Loop through passing 10 at a time to AWS
for (var i = 0; i < count; i++)
{
    var prodASINToSend = prodASINs.Skip(i * 10).Take(10).ToList(); 
    //Send to AWS
}

或者您不想将它们全部加载到内存中.

Or if you don't want to load them all into memory.

var count = dc.aboProducts.Count();
for (var i = 0; i < count; i++)
{
    List<string> prodASIN = dc.aboProducts.OrderBy(a => a.Id).Select(a => a.asin).Skip(i * 10).Take(10).ToList(); 
    //Send to AWS
}

这篇关于将结果从数据库拆分为&amp; quot;&quot;&quot;共10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆