Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 基于其他实体内容对实体排序_C#_.net_Entity Framework_Entity Framework 5 - Fatal编程技术网

C# 基于其他实体内容对实体排序

C# 基于其他实体内容对实体排序,c#,.net,entity-framework,entity-framework-5,C#,.net,Entity Framework,Entity Framework 5,我的问题是我不知道如何编写这个查询 我有一个完整的对话 public class Conversation : Entity { protected Conversation() { } [Required] public DateTime CreationDate { get; protected set; } public virtual HashSet<Message> Messages { ge

我的问题是我不知道如何编写这个查询

我有一个完整的对话

   public class Conversation : Entity
    {
        protected Conversation() { }

        [Required]
        public DateTime CreationDate { get; protected set; }

        public virtual HashSet<Message> Messages { get; set; }
}
公共类对话:实体
{
受保护的会话(){}
[必需]
public DateTime CreationDate{get;protected set;}
公共虚拟哈希集消息{get;set;}
}
和实体消息

public class Message : Entity<long>
    {
        protected Message()
        { }

        public DateTime CreationDate { get; protected set; }

        [Required]
        public string Msg { get; protected set; }
}
公共类消息:实体
{
受保护的消息()
{ }
public DateTime CreationDate{get;protected set;}
[必需]
公共字符串Msg{get;protected set;}
}
我想检索由上面最近写的消息排序的对话

我所说的“最近”是指在对话中写得最详细的


有人可以帮我吗?

只需查看每个对话的最大消息创建数据:

var query = conversations.OrderByDescending(c => c.Messages.Max(m => n.CreationDate))

为什么要使用
HashSet
(特别是因为
消息
没有覆盖您显示的
Equals
GetHashCode
)?我在实体的通用实现上覆盖了它。但这不是我的问题。