Is there a way to use the method described in this answer No FindAsync() method on IDbSet for DbSet properties of a DbContext?
Edit:
The answer linked contains a description how to build a interface inheriting from IDbSet and adding support for the SearchAsync method of the DbSet class. I understand everything which Keith Payne has written, but I don’t know how I can use it in DbContext.
For example I’ve a DbContext which looks something like this:
public class MyContext : DbContext
{
public DbSet<Customer> Customers { get; set; }
}
How can I use MyDbSet (class described in the answer.) or a similar class, instead of DbSet?
public class MyContext : DbContext
{
public MyDbSet<Customer> Customers { get; set; }
}
The problem is now, that Entity Framework seem to generate only tables for properties of type IDbSet or DbSet.
You have regular DbSet on your context and create an adapter adding the requested interface.
Now you can create a
DbSetAdapater
when you need it and get an IAsyncDbSet. You could duplicate your properties as EF seems to ignore them or add anToAsyncDbSet()
extension method toIDbSet<T>