コード例 #1
0
        public void Add(T entity)
        {
            EntityEntry dbEntityEntry = context.Entry <T>(entity);

            context.Set <T>().Add(entity);

            context.SaveChanges();
        }
コード例 #2
0
 public bool Delete(T entity)
 {
     _dbContext.Set <T>().Remove(entity);
     try
     {
         return(_dbContext.SaveChanges() > 0);
     }
     catch (Exception)
     {
         return(false);
     }
 }
コード例 #3
0
        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());
        }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: Repository.cs プロジェクト: htarikyavas/Article
 public Repository(ArticleContext dbContext)
 {
     this.dbContext = dbContext;
     this.Table     = dbContext.Set <T>();
 }
コード例 #6
0
 public Repository(ArticleContext context)
 {
     this._context = context;
     this._dbSet   = context.Set <TEntity>();
 }
コード例 #7
0
 public Repository(ArticleContext context)
 {
     _db    = context;
     _dbSet = context.Set <T>();
 }