【发布时间】:2015-07-16 07:57:24
【问题描述】:
假设我们有这个模型:
public class Tiers
{
public List<Contact> Contacts { get; set; }
}
和
public class Contact
{
public int Id { get; set; }
public Tiers Tiers { get; set; }
public Titre Titre { get; set; }
public TypeContact TypeContact { get; set; }
public Langue Langue { get; set; }
public Fonction Fonction { get; set; }
public Service Service { get; set; }
public StatutMail StatutMail { get; set; }
}
使用 EF7,我想用一条指令从 Tiers 表中检索所有数据、Contact 表中的数据、Titre 表中、TypeContact 表中的数据等等。使用 Include/ThenInclude API,我可以编写如下内容:
_dbSet
.Include(tiers => tiers.Contacts)
.ThenInclude(contact => contact.Titre)
.ToList();
但是在 Titre 属性之后,我不能包含其他引用,例如 TypeContact、Langue、Fonction ... Include 方法建议使用 Tiers 对象,然后 ThenInclude 建议使用 Titre 对象,而不是 Contact 对象。如何包含我的联系人列表中的所有引用?我们可以通过一条指令实现这一目标吗?
【问题讨论】:
标签: asp.net-core-mvc entity-framework-core