public void Add(T entity) { EntityEntry dbEntityEntry = context.Entry <T>(entity); context.Set <T>().Add(entity); context.SaveChanges(); }
public bool Delete(T entity) { _dbContext.Set <T>().Remove(entity); try { return(_dbContext.SaveChanges() > 0); } catch (Exception) { return(false); } }
public List <Article> GetPaggingList(Expression <Func <Article, bool> > filter = null, int skip = 0, int take = 10) { var myResult = _context.Set <Article>().AsQueryable(); if (filter != null) { myResult = myResult.Where(filter); } return(myResult.Skip(skip).Take(take).ToList()); }
public IEnumerable <T> SelectAll() { logger.LogInformation("Called GET method."); if (!memoryCache.TryGetValue(cacheKey, out IEnumerable <T> entityList)) { // If memory has not value then retrieve data from database and set cache. entityList = context.Set <T>().ToList(); var cacheOptions = new MemoryCacheEntryOptions { AbsoluteExpiration = DateTime.Now.AddMinutes(5), Priority = CacheItemPriority.Normal }; memoryCache.Set(cacheKey, entityList, cacheOptions); logger.LogInformation("List has been retrieved from database."); } else { logger.LogInformation("List has been retrieved from cache."); } return(entityList); }
public Repository(ArticleContext dbContext) { this.dbContext = dbContext; this.Table = dbContext.Set <T>(); }
public Repository(ArticleContext context) { this._context = context; this._dbSet = context.Set <TEntity>(); }
public Repository(ArticleContext context) { _db = context; _dbSet = context.Set <T>(); }