title: Entity Framework: how to include protected Collection<>?
body: <p>I've got a collection of addresses which can contain multiple addresses for a Customer (delivery, invoice, etc.)</p>
  
  <p>Now, I'm trying to use <code>.Include(s =&gt; s.Addresses)</code> on my Customer class. Addresses and the derivative DeliveryAddress are defined like this:</p>
  
  <pre class="lang-cs prettyprint-override"><code>protected virtual ICollection&lt;Address&gt; Addresses
  {
     get { return _addresses ?? (_addresses = new Collection&lt;Address&gt;()); }
     set { _addresses = value; }
  }
  
  [NotMapped]
  public Address DeliveryAddress
  {
     get { return GetAddress(AddressType.Delivery); }
  }
  
  private Address GetAddress(AddressType type)
  {
     return Addresses.FirstOrDefault(a =&gt; a.Type == type);
  }
  </code></pre>
  
  <p>Since it's a protected property, I've found a solution for this on <a href="https://owencraig.com/mapping-but-not-exposing-icollections-in-entity-framework/" rel="nofollow noreferrer">Mapping but not exposing ICollections in Entity Framework</a></p>
  
  <p>I Also found the following post, but this is about mappings instead of includes:
  <a href="https://stackoverflow.com/questions/9311954/how-to-map-a-protected-property-in-ef-4-3-code-first">How to map a protected property in EF 4.3 code first</a></p>
  
  <p>Here they add the following to the class containing the protected property <code>public static Expression&lt;Func&lt;Parent, ICollection&lt;Child&gt;&gt;&gt; ChildrenAccessor = f =&gt; f.ChildrenStorage;</code>. </p>
  
  <p>So I've added the same to my Customer class like so:
  <code>public static Expression&lt;Func&lt;Customer, ICollection&lt;Address&gt;&gt;&gt; AddressesAccessor = f =&gt; f.Addresses;</code></p>
  
  <p>And then i'm able to use the include with <code>Include(Customer.AddressesAccessor)</code>
  This works great for mappings, but I'm not getting it to work with the Include method. It keeps telling me the following:</p>
  
  <blockquote>
    <p>System.InvalidOperationException: A specified Include path is not valid. The EntityType 'Web.DataAccess.Customer' does not declare a navigation property with the name 'Addresses'.</p>
  </blockquote>
  
  <p>When I change the signature of the Addresses property from <code>protected</code> back to <code>public</code> all works fine.</p>
  
  <p>Does anyone know how to make this work for protected collections?</p>