我有两个表-博客和帖子(一对多关系)。
我想获取所有博客数量至少为3的博客,并按发布日期仅获取3个博客和订单列表的帖子。
我正在尝试:
_context.Blogs.Where(x => x.IsActive && x.Posts.Count >= 3).OrderByDescending(p => p.Posts.OrderByDescending(x => x.PublishDate)).ToList();
但我收到一条错误消息:
ArgumentException: At least one object must implement IComparable.
更新:
好的,我认为按发布日期进行排序将是一个问题。
我还在Blog表中的LastBuildDate属性。那么如何按LastBuildDate订购?
最佳答案
试试这个,我还没测试过。
_context.Blogs.Where(x => x.IsActive && x.Posts.Count >= 3).OrderByDescending(x => x.LastBuildDate).ToList();
关于c# - 按列表中的子属性排序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42447623/