title: Implement custom navigation property in Entity Framework 6.4.4 database first
body: <p>In my database, there's an existing relationship between two tables based on a non-primary key column with an unique index applied. This is, afaik, not yet supported by EF6 database first. Therefore, I want to implement a custom navigation property, but I'm not quite sure, how to do so. For now, I just added the following property to my code:</p>
  <pre class="lang-cs prettyprint-override"><code>public partial class MyEntity // extends the auto-generated code
  {
      public List&lt;SomeOtherEntity&gt; CustomNavigationProperty
      {
          get
          {
              using DatabaseEntities db = new();
  
              return db.SomeOtherEntity
                  .Where(e =&gt; e.CustomID == this.CustomID)
                  .ToList();
          }
      }
  }
  </code></pre>
  <p>This approach works in principle, but it eliminates the current database context. It also doesn't support async database calls. I don't know, if there is any way to do the subquery based on <code>MyEntity</code>'s current database context. Unfortunately, there is no <code>this.Context</code> property or something similar. Or maybe there is an even better implementation for such a task.</p>
  <p>How would you implement such a custom navigation property?</p>