public IEnumerable <TEntity> GetAll() { // Note that here I've repeated Context.Set<TEntity>() in every method and this is causing // too much noise. I could get a reference to the DbSet returned from this method in the // constructor and store it in a private field like _entities. This way, the implementation // of our methods would be cleaner: // // _entities.ToList(); // _entities.Where(); // _entities.SingleOrDefault(); // // I didn't change it because I wanted the code to look like the videos. But feel free to change // this on your own. return(CurrentDbSet.Cast <TEntity>().ToList()); }
public TEntity SingleOrDefault(Expression <Func <TEntity, bool> > predicate) { return(CurrentDbSet.Cast <TEntity>().SingleOrDefault(predicate)); }
public IEnumerable <TEntity> Find(Expression <Func <TEntity, bool> > predicate) { return(CurrentDbSet.Cast <TEntity>().Where(predicate)); }
public TEntity Get(int id) { // Here we are working with a DbContext, not PlutoContext. So we don't have DbSets // such as Courses or Authors, and we need to use the generic Set() method to access them. return(CurrentDbSet.Cast <TEntity>().Find(id)); }