Exemplo n.º 1
0
        public void Add(T entity)
        {
            _ctx.Set <T>().Add(entity);

            /*
             * without class  => where T : class,new()
             * _ctx.Set(entity.GetType()).Add(entity);
             */
            _ctx.SaveChanges();
        }
        protected override void Seed(NewsContext context)
        {
            var defaultRssSources = new List <NewsRssSource>
            {
                NewsRssSource.Create("Nasdaq: Business News", "http://articlefeeds.nasdaq.com/nasdaq/categories?category=Business", true),
                NewsRssSource.Create("Nasdaq: Forex and currencies", "http://articlefeeds.nasdaq.com/nasdaq/categories?category=Forex+and+Currencies", true),
                NewsRssSource.Create("DailyFX: Forex market news and analysis", "https://rss.dailyfx.com/feeds/all", true)
            };

            context.Set <NewsRssSource>().AddOrUpdate(x => x.Url, defaultRssSources.ToArray());

            context.SaveChanges();
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Delete(int id)
        {
            var news = await _context.Set <News>().FirstOrDefaultAsync(n => n.Id == id);

            if (news == null)
            {
                return(NotFound());
            }

            _context.Remove(news);
            await _context.SaveChangesAsync();

            _eventBus.Publish(new NewsRemoveEvent(id));

            return(NoContent());
        }
Exemplo n.º 4
0
 protected async Task AddTodb(IEnumerable <Models.News> items)
 {
     _db.Set <Models.News>().AddRange(items);
     await _db.SaveChangesAsync();
 }
Exemplo n.º 5
0
 public IQueryable <T> GetAll()
 {
     return(dbContext.Set <T>());
 }
Exemplo n.º 6
0
 public GenericRepository()
 {
     context = new NewsContext();
     _dbset  = context.Set <Tentity>();
     //_/*dbset.Where(x => x.)*/
 }
Exemplo n.º 7
0
 public BaseRepository(string connectionString)
 {
     DB         = new NewsContext(connectionString);
     Collection = DB.Set <TEntity>();
 }
Exemplo n.º 8
0
 public Repository(NewsContext db)
 {
     Db    = db;
     DbSet = db.Set <TEntity>();
 }
Exemplo n.º 9
0
 public Repository(NewsContext context)
 {
     this.context = context;
     this.set     = context.Set <T>();
 }
Exemplo n.º 10
0
 public IQueryable <TModel> GetAll()
 {
     return(_dbContext.Set <TModel>().AsNoTracking());
 }
Exemplo n.º 11
0
        /// <summary>
        /// 取得 最新消息標題清單
        /// </summary>
        /// <returns></returns>
        public List <GetNewsListReturnDTO> GetNewsTitleList()
        {
            List <GetNewsListReturnDTO> lsreturnDto = new List <GetNewsListReturnDTO>();

            try
            {
                IEnumerable <News> dbSet = _dbContext.Set <News>().Where(o => o.IsEnable == true).OrderByDescending(o => o.CreateTime);

                foreach (News item in dbSet)
                {
                    GetNewsListReturnDTO newDto = new GetNewsListReturnDTO()
                    {
                        NewsID       = item.ID,
                        NewsTitle    = item.Title,
                        NewsCategory = item.Category,
                        CreateDate   = item.CreateTime
                    };
                    lsreturnDto.Add(newDto);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(lsreturnDto);
        }
Exemplo n.º 12
0
 public virtual List <T> BringItAll()
 {
     return(db.Set <T>().ToList());
 }
Exemplo n.º 13
0
 /// <summary>
 /// 获取单个实体
 /// </summary>
 /// <param name="predicate"></param>
 /// <returns></returns>
 public virtual async Task <TEntity> FirstOrDefaultAsync(Expression <Func <TEntity, bool> > predicate)
 => await _BaseDb.Set <TEntity>().AsNoTracking().FirstOrDefaultAsync(predicate);