/// <summary> /// Returns a single object with a primary key of the provided id /// </summary> /// <remarks>Asynchronous</remarks> /// <param name="id">The primary key of the object to fetch</param> /// <returns>A single object with the provided primary key or null</returns> public async Task <TEntity> GetAsync(int id, bool option = false) { var entity = await Context.Set <TEntity>().FindAsync(id); if (!option) { Context.Entry(entity).State = EntityState.Detached; } return(entity); // return await this.entities.FindAsync(id); }
public IQueryable <TEntity> GetAll() { try { return(RepositoryPatternDemoContext.Set <TEntity>()); } catch (Exception ex) { throw new Exception($"Couldn't retrieve entities: {ex.Message}"); } }
/// <summary> /// The contructor requires an open DataContext to work with /// </summary> /// <param name="context">An open DataContext</param> public RepositoryMaintenanceMk2(MaintenanceContext context) { this.Context = context; try { this.Entities = context.Set <TEntity>(); } catch { this.Queries = context.Query <TEntity>(); } }
/// <summary> /// The contructor requires an open DataContext to work with /// </summary> /// <param name="context">An open DataContext</param> public RepositoryMaintenance(MaintenanceContext context) { this.Context = context; Entities = context.Set <TEntity>(); }