Advertisement
Guest User

RepositorioBase

a guest
Nov 17th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. protected ProjetoCarteiraWebContexto bd = new ProjetoCarteiraWebContexto();
  2.  
  3.         public void Adicionar(TEntity objeto)
  4.         {
  5.             bd.Set<TEntity>().Add(objeto);
  6.             bd.SaveChanges();
  7.         }
  8.  
  9.         public void Alterar(TEntity objeto)
  10.         {
  11.             bd.Entry(objeto).State = System.Data.Entity.EntityState.Modified;
  12.             bd.SaveChanges();
  13.         }
  14.  
  15.         public TEntity ConsultarPorId(int id)
  16.         {
  17.             return bd.Set<TEntity>().Find(id);
  18.         }
  19.  
  20.         public IEnumerable<TEntity> ConsultarTodos()
  21.         {
  22.             return bd.Set<TEntity>().ToList();
  23.         }
  24.  
  25.         public void Remover(TEntity objeto)
  26.         {
  27.             bd.Set<TEntity>().Remove(objeto);
  28.             bd.SaveChanges();
  29.         }
  30.  
  31.         public void Dispose()
  32.         {
  33.             bd.Dispose();
  34.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement