Include several references on the second level

前端 未结 2 647
广开言路
广开言路 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:36

    For completeness' sake:

    It is also possible to include nested properties directly via Include in case they are not collection properties like so:

    _dbSet
        .Include(tier => tier.Contact.Titre)
        .Include(tier => tier.Contact.TypeContact)
        .Include(tier => tier.Contact.Langue);
    
    0 讨论(0)
  • 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.
    
    0 讨论(0)
提交回复
热议问题