我有一个ticket
实体,其ticketNotes
(0到多),并希望在查询故障单时撤回创建每个记事的用户详细信息。
我使用以下代码查询故障单
var ticket = (from t in context.Tickets
.Include(t=>t.Site)
.Include(t=>t.Caller)
.Include(t=>t.Caller.Site)
.Include(t => t.Notes)
.Include(t=>t.OpenedByUser)
select t).First(t => t.TicketId == ticketId);
我的TicketNote
班级是:
public class TicketNote
{
public Guid TicketNoteId { get; set; }
public string NoteText { get; set; }
public DateTime CreatedTime { get; set; }
public Guid TicketId { get; set; }
public virtual Ticket Ticket { get; set; }
public bool ReadOnly { get; set; }
public DateTime? DateTimeDeleted { get; set; }
public Guid TenantId { get; set; }
[Required]
[DefaultValue(typeof(Guid), "00000000-0000-0000-0000-000000000000")]
public Guid CreatedByUserId { get; set; }
[ForeignKey("CreatedByUserId")]
public virtual User CreatedByUser { get; set; }
}
我想添加
.Include(t => t.Notes.CreatedByUser)
然而,由于笔记是一个集合,我没有得到选项。
请告知最佳方法,以实现撤回目前为NULL的CreatedByUser。
由于
答案 0 :(得分:2)
您可以包含更复杂的语句来获取多级集合。请尝试以下方法:
.Include(t => t.Notes.Select(n => n.CreatedByUser))
答案 1 :(得分:0)
您有Notes
个变量,其中包含属性ticket.Notes.Select(t => n.CreatedByUser)
。
为了表现,你可以使用
hadoop-env.sh