我需要通过Messages Answers对邮件进行分组,如下所示:
消息回答id = 4 /父消息id = 1
消息ID = 5
消息模型:
public class Message
{
// Primary properties
public int Id { get; set; }
public string NameFrom { get; set; }
public string EmailFrom { get; set; }
public string TelephoneFrom { get; set; }
public string NameTo { get; set; }
public string EmailTo { get; set; }
public string TelephoneTo { get; set; }
public string Title { get; set; }
public string MessageText { get; set; }
public bool? Approved { get; set; }
public DateTime DateCreated { get; set; }
public DateTime? DateRead { get; set; }
// Navigation properties
public Member MemberFrom { get; set; }
public Member MemberTo { get; set; }
public MessageType MessageType { get; set; }
public Message MessageParent { get; set; }
public Ad Ad { get; set; }
public Ask Ask { get; set; }
}
在视图中展示它:
@foreach (var item in Model)
{
<div class="message_link_container" id="linkmessage_@item.Id">
<ul class="estr_message" id="estrmessage_@item.Id">
<li id="email_@item.Id">
<p>@if(item.MessageParent_Id == 0){ if(string.IsNullOrEmpty(item.NameFrom)) { @item.EmailFrom } else { @item.NameFrom } }</p>
</li>
<li id="title_@item.Id">
<p>@item.Title</p>
</li>
<li id="date_@item.Id">
<p>@item.DateCreated</p>
</li>
</ul>
</div>
}
答案 0 :(得分:6)
var model=Messages
.OrderBy(o=>o.MessageParent_Id==0?Id:o.MessageParent_Id)
.ThenBy(o=>o.Id);