Пример #1
0
 /// <summary>
 /// Método que retorna uma lista com todos registros de uma tabela.
 /// </summary>
 /// <returns></returns>
 public List <TEntity> GetAll()
 {
     using (var db = new OSEventosContext())
     {
         return(db.Set <TEntity>().AsNoTracking().ToList());
     }
 }
Пример #2
0
 /// <summary>
 /// Remove um registro do DB.
 /// </summary>
 /// <param name="obj"></param>
 public void Remove(TEntity obj)
 {
     using (var db = new OSEventosContext())
     {
         db.Set <TEntity>().Remove(obj);
         db.SaveChanges();
     }
 }
Пример #3
0
 /// <summary>
 /// Realiza a atualização de um registro.
 /// </summary>
 /// <param name="obj"></param>
 public void Update(TEntity obj)
 {
     using (var db = new OSEventosContext())
     {
         db.Entry(obj).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Пример #4
0
 /// <summary>
 /// Método que busca um objeto pelo seu Id.
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public TEntity GetById(object id)
 {
     using (var db = new OSEventosContext())
     {
         db.Set <TEntity>().AsNoTracking();
         return(db.Set <TEntity>().Find(id));
     }
 }
Пример #5
0
 /// <summary>
 /// Remove varios registros
 /// </summary>
 /// <param name="predicate"></param>
 public void Remove(Func <TEntity, bool> predicate)
 {
     using (var db = new OSEventosContext())
     {
         db.Set <TEntity>().Where(predicate).ToList()
         .ForEach(del => db.Set <TEntity>().Remove(del));
         db.SaveChanges();
     }
 }
Пример #6
0
 /// <summary>
 /// Método que insere um registro.
 /// </summary>
 /// <param name="obj"></param>
 public TEntity Add(TEntity obj)
 {
     using (var db = new OSEventosContext())
     {
         db.Set <TEntity>().Add(obj);
         db.SaveChanges();
         return(obj);
     }
 }
        public void Dispose(OSEventosContext context)
        {
            if (context != null)
            {
                context.Dispose();
            }

            GC.SuppressFinalize(context);
        }
Пример #8
0
 public EventoRepository(OSEventosContext context) : base(context)
 {
 }
Пример #9
0
 public BaseRepository(OSEventosContext context)
 {
     db = context;
 }