2 votes

Class Base Repository does not assume DBset Property

Is this trying to migrate from entityframework to core a class Repository base where you have a property that defines the dbset like this:

protected DbSet dBset
            return Context.Set<TObject>();

when you implement the filter method

protected IQueryable Filter(Expression<Func<TObject, bool>> predicate)
        return dBset.Where(predicate).AsQueryable();
        // TODO: Control de excepciones

throws error:

'DbSet' does not contain a definition for 'Where' and the best overload for the extension method 'Queryable.Where(IQueryable, Expression>)' requires a receiver of type 'IQueryable'

I do not understand because it does not assume the dBset that I've defined as a property of this class but when I put the line with

return Context.Set<Tobject>();

with this line do not get the error, which is what is happening?


Leandro Tuttini Points 25288

Analyzing similar example implementations, such as:

Generic Repository Pattern implemented in .NET Core with EF Core

I don't see that they have a problem, you could see change, using something like this:

 protected IEnumerable<TObject> Filter(Func<TObject, bool> predicate)
    return Context.Set<TObject>().Where(predicate);

removing AsQueryable() and return the object list with the response of its execution


HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by: