public class InvestorMailing
{
public string To { get; set; }
public IEnumerable<string> Attachments { get; set; }
public int AttachmentCount { get; set; }
public long AttachmentSize { get; set; }
}
我有一个IList<InvestorMailing> mailingList
。如果附件大小大于x,那么我需要将我的对象分成块。有没有一个简单的方法来做到这一点?如何根据某些属性将对象分块为块?
编辑:
这是如何我产生我的邮件:
var groupedMailings = mailingList.GroupBy(g => g.GroupBy);
var investorMailings = groupedMailings.Select(
g => new DistinctInvestorMailing
{
Id = g.Select(x => x.Id).FirstOrDefault(),
To = g.Key.Trim(),
From = g.Select(x => x.From).FirstOrDefault(),
FromName = g.Select(x => x.FromName).FirstOrDefault(),
Bcc = g.Select(x => x.Bcc).FirstOrDefault(),
DeliveryCode = g.Select(x => x.DeliveryCode).FirstOrDefault(),
Subject = g.Select(x => x.Subject).FirstOrDefault(),
Body = g.Select(x => x.Body).FirstOrDefault(),
CommentsOnStatus = g.Select(x => x.CommentsOnStatus).FirstOrDefault(),
Attachments = g.Select(x => x.AttachmentPath),
AttachmentCount = g.Select(x => x.AttachmentPath).Count(),
AttachmentSize = g.Sum(x => x.AttachmentSize),
MailType = g.Select(x => x.MessageType).FirstOrDefault()
}
).ToList();
你想拆分什么? InvestorMailings的列表或个人InvestorMailing的附件? – dtb 2010-04-22 17:34:09
InventorMailing是一个对象,每个对象都有自己的AttachmentCount属性。你什么时候想拆分?即使列表中的单个项目大于x,您还想分割吗? – azamsharp 2010-04-22 17:35:16
几乎相同http://stackoverflow.com/questions/2678008/how-to-split-linq-grouping – 2010-04-22 18:18:16