1

im new in MVC,i have a project used repository and unit of work,in the repository of the project its written :

private DbContext context;
    private DbSet<TEntity> dbQueryable;

    public GenericEFRepository(DbContext context) : base(context.Set<TEntity>())
    {
        this.context = context;
        this.dbQueryable = (DbSet<TEntity>)this.Queryable;
    }

can anyone explain what does it do and tell me what :base is?

moris62
  • 983
  • 1
  • 14
  • 41

1 Answers1

1

Well from the code it looks that you are using Entity Framework. First two lines are just objects of EF. The GenericEFRepository is generic method which must be the part of Generic Repository I guess.

With : base(context.Set<TEntity>() code, you are calling constructor of your base class. Look at the definition of GenericEFRepository class where you have specified the base class.

Finally, the method body returns IQueryable which you can consume in your calling code.


But, this all needs to be improved. Generic repository is considered an anti pattern. I suggest you understand the repository pattern before you implement it. Returning IQueryable breaks the basic purpose of repository.

Please refer following answers for more information:

https://stackoverflow.com/a/49974458/5779732
https://stackoverflow.com/a/49850950/5779732

Amit Joshi
  • 15,448
  • 21
  • 77
  • 141