【发布时间】:2018-03-15 06:20:01
【问题描述】:
我们当前的系统默认使用延迟加载(我将禁用它,但现在无法完成)
对于这个基本查询,我想返回两个表,CustomerNote 和 Note。
这是我的查询
using (var newContext = new Entities(true))
{
newContext.Configuration.LazyLoadingEnabled = false;
var result = from customerNotes in newContext.CustomerNotes.Include(d=>d.Note)
join note in newContext.Notes
on customerNotes.NoteId equals note.Id
where customerNotes.CustomerId == customerId
select customerNotes;
return result.ToList();
}
但我的结果只包含 CustomerNote 表中的数据
链接的实体 Customer 和 Note 都是空的,我在这里做错了什么?
我得到了它,这比我在其他地方找到的要简单得多
Context.Configuration.LazyLoadingEnabled = false;
var result = Context.CustomerNotes.Where<CustomerNote>(d => d.CustomerId == customerId)
.Include(d=>d.Note)
.Include(d=>d.Note.User);
return result.ToList();
这将返回我的 CustomerNote 表、相关的 Notes 以及来自 Notes 的相关用户。
【问题讨论】:
标签: entity-framework entity-framework-6 lazy-loading