“questa è classe, coglionazzo!” (cit.) o “si salvi chi può” (cit.)?
public class DiscussionGroupDto
{
public int Id;
public string Description;
public string Name;
public int NumberOfPosts;
public int NumberOfThreads;
public DiscussionMessageDto LastMessage;
}
public class DiscussionMessageDto
{
public int Id;
public string AuthorName;
public DateTime DateOfPublishing;
public string Subject;
public int ThreadId;
}
IList<DiscussionGroupDto> groups = (from g in domain.DiscussionGroupSet
let threadCount = (from t in domain.DiscussionThreadSet where t.DiscussionGroup==g && t.IsReadOnly==false select t).Count()
let postCount = (from t in domain.DiscussionThreadSet where t.DiscussionGroup == g from m in t.Messages select m.Id).Count()
let lastMessage = (from t in domain.DiscussionThreadSet where t.DiscussionGroup == g from m in t.Messages orderby m.DateOfPublishing descending select new DiscussionGroupCategoryDto.DiscussionMessageDto { Id = m.Id, AuthorName = m.AuthorName, DateOfPublishing = m.DateOfPublishing, Subject = m.Subject, ThreadId = m.DiscussionThread.Id }).FirstOrDefault()
where g.Category.Id == c.Id orderby g.Name select new DiscussionGroupCategoryDto.DiscussionGroupDto { Id = g.Id, Description = g.Description, Name = g.Name, NumberOfThreads=threadCount, NumberOfPosts=postCount, LastMessage=lastMessage }).ToList();
posted @ mercoledì 3 giugno 2009 16:44