假设我们有这个模型:
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对象。我该如何在我的联系人列表中包括所有这些引用?我们能否用一条指令完成这个操作?
var contacts = _dbSet.Include(tiers => tiers.Contacts);
contacts.ThenInclude(contact => contact.Titre);
contacts.ThenInclude(contact => contact.TypeContact);
contacts.ThenInclude(contact => contact.Langue);
这样行不行? - Doug