Include several references on the second level

前端 未结 2 649
广开言路
广开言路 2020-12-23 10:53

Assume we have this model :

public class Tiers
{
    public List Contacts { get; set; }
}

and

public class C         


        
2条回答
  •  情深已故
    2020-12-23 11:46

    .ThenInclude() will chain off of either the last .ThenInclude() or the last .Include() (whichever is more recent) to pull in multiple levels. To include multiple siblings at the same level, just use another .Include() chain. Formatting the code right can drastically improve readability.

    _dbSet
        .Include(tiers => tiers.Contacts).ThenInclude(contact => contact.Titre)
        .Include(tiers => tiers.Contacts).ThenInclude(contact => contact.TypeContact)
        .Include(tiers => tiers.Contacts).ThenInclude(contact => contact.Langue);
        // etc.
    

提交回复
热议问题