title: How to query a property bag entity type in EFCore5?
body: <p>In EFCore5, implicit tables are saved as <code>Dictionary&lt;TKey, object&gt;</code> sets, knows as <a href="https://docs.microsoft.com/en-us/ef/core/modeling/shadow-properties#property-bag-entity-types" rel="nofollow noreferrer">Property Bag Entity Types</a>. However, I cannot figure out how to create a LINQ query with a Where() clause that compiles for MySQL for such a property bag entity type.</p>
  <p>For example, this code successfully retrieves the <code>IQueryable</code> reference to an intermediate table (generated by EFcore5's implicity many-to-many feature) given the <code>ISkipNavigation</code>:</p>
  <pre><code>ISkipNavigation nav = // some many-to-many relationship
  
  IQueryable&lt;Dictionary&lt;string, object&gt;&gt; intermediateTable = 
    context.Set&lt;Dictionary&lt;string, object&gt;&gt;(nav.JoinEntityType.Name);
  </code></pre>
  <p>And this code successfully retrieves all the entries in the intermediate table:</p>
  <pre><code>List&lt;Dictionary&lt;string, object&gt;&gt; joins = await intermediateTable.ToListAsync();
  </code></pre>
  <p>In the resulting <code>List</code>, each <code>Dictionary</code> has just one key/value (representing the row).</p>
  <p>However, I cannot figure out how to add a <code>.Where()</code> clause to the LINQ query which will compile:</p>
  <pre><code>joinTable.Where(d =&gt; d.Keys.First() == &quot;foo&quot;).ToList();
  joinTable.Where(d =&gt; d.Keys.Any(k =&gt; k == &quot;foo&quot;)).ToList();
  </code></pre>
  <p>The error is:</p>
  <blockquote>
  <p>Translation of member 'Keys' on entity type 'MachinePartMachineProfile (Dictionary&lt;string, object&gt;)' failed. This commonly occurs when the specified member is unmapped. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'</p>
  </blockquote>
  <p>I do not wish to do client-side parsing for performance reasons (the join table will be to big).</p>
  <p>I note that the type reported by the error is <code>MachinePartMachineProfile (Dictionary&lt;string, object&gt;)</code>. Some investigation showed that <a href="https://github.com/dotnet/efcore/blob/b970bf29a46521f40862a01db9e276e6448d3cb0/src/EFCore/Metadata/Conventions/ManyToManyJoinEntityTypeConvention.cs#L129-L130" rel="nofollow noreferrer">these types are being generated</a> based upon the static <code>Model.DefaultPropertyBagType</code> (which is a <code>Dictionary&lt;string, object&gt;</code>). But despite staring at the EFCore code base, I cannot discern how to correctly query such a default property bag type.</p>
  <p>I am using MySQL as my database, if it is relevant.</p>