/// <summary> /// /// </summary> /// <param name="where"></param> /// <param name="navigationProperties"></param> /// <returns></returns> public virtual TEntity GetSingle(Func <TEntity, bool> where, params Expression <Func <TEntity, object> >[] navigationProperties) { TEntity item = null; using (var context = new DbITSClinicNinjaContext()) { IQueryable <TEntity> dbQuery = context.Set <TEntity>(); //Apply eager loading foreach (Expression <Func <TEntity, object> > navigationProperty in navigationProperties) { dbQuery = dbQuery.Include <TEntity, object>(navigationProperty); } item = dbQuery .AsNoTracking() //Don't track any changes for the selected item .FirstOrDefault(where); //Apply where clause } return(item); }
public async Task <TEntity> GetAsync(int id) { return(await Context.Set <TEntity>().FindAsync(id)); }
/// <summary> /// Public Constructor,initializes privately declared local variables. /// </summary> /// <param name="context"></param> public GenericRepository(DbITSClinicNinjaContext context) { this.Context = context; this.DbSet = context.Set <TEntity>(); }