title: .NET Core - EntityFrameworkCore - Unable to cast object of type 'Query.Internal.EntityQueryable` to type 'DbSet`
body: <p>I try to implement a search with entity when a search field is provided</p>
  <p>but I get a weird casting error I just dont understand</p>
  <pre><code>Unable to cast object of type 'Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[SomeApp.Models.Partner]' to type 'Microsoft.EntityFrameworkCore.DbSet`1[SomeApp.Models.Partner]'.
  </code></pre>
  <p>here is the code of my controller entry point</p>
  <p>I tried forcing the cast, but apparently there is something wrong with my code</p>
  <pre><code>[HttpPost]
  public async Task&lt;ActionResult&lt;PartnersFetch&gt;&gt; GetPartners(PartnersSearch partnersSearch)
  {
      DbSet&lt;Partner&gt; data = _context.Partners;
      if (partnersSearch.SearchById != null)
      {
          // the following line causes problems :
          data = (DbSet &lt;Partner&gt;) data.Where( p =&gt; p.Id == partnersSearch.SearchById.GetValueOrDefault());
      }
          
  </code></pre>
  <p>thanks for helping me on this</p>