This works
var invoices = this.myContext.FilterByCustomer(this.myContext.Invoices, customerId);
It is implemented as:
public partial class MyContext : DbContext
{
public IQueryable<T> FilterByCustomer<T>(IQueryable<T> queryableEntityCollection, int customerId) where T : class, ICustomerEntity
{
// I need to query entities from MyContext here
// This implementation already works
}
}
But I want this
var invoices = this.myContext.Invoices.FilterByCustomer(customerId);
If I implement an extension method on the IQueryable (DbSet), seems like I have to pass the MyContext
as a parameter, which I don't like.
public static IQueryable<T> FilterByCustomer<T>(this IQueryable<T> queryableEntityCollection, MyContext context, int customerId) where T : class, ICustomerEntity
{
// I need to query entities from MyContext here
// This WOULD work, I would be able to query other tables on 'context', but I don't like passing the context as parameter here
// I don't want this implementation
}
How can I implement an IQueryable extension which doesn't require me to pass the context as parameter?
public IQueryable<T> FilterByCustomer<T>(IQueryable<T> queryableEntityCollection, int customerId) where T : class, ICustomerEntity
{
// I need to query entities from MyContext here, without passing MyContext as a parameter
// I want such implementation
}
Is that possible at all?