我想按最后评论日期或帖子日期订购帖子列表。
这是课程:
public class Post
{
public int Id { get; set; }
public string Text { get; set; }
public System.DateTime DatePosted { get; set; }
public ICollection<Comment> Comments { get; set; }
}
public partial class Comment
{
public int Id { get; set; }
public int PostId { get; set; }
public string Text { get; set; }
public System.DateTime DateCommented { get; set; }
}
理想的代码(甚至不编译)将是:
IEnumerable <Post> posts = MVPMetroEntities.Posts
.OrderByDescending(p =>
p.DatePosted || p.Comments.Max(c=>c.DateCommented));
有任何想法吗 ?谢谢