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