Exemplo n.º 1
0
 public Product Create(Product product)
 {
     using var Context = new NorthWindContext();
     Context.Add(product);
     Context.SaveChanges();
     return(product);
 }
Exemplo n.º 2
0
 public void Delete(int id)
 {
     using var Context = new NorthWindContext();
     Context.Remove(new Product {
         Id = id
     });
     Context.SaveChanges();
 }
Exemplo n.º 3
0
 public void Update(Product product)
 {
     using var Context = new NorthWindContext();
     Context.Update(product);
     Context.SaveChanges();
 }
Exemplo n.º 4
0
 public Product GetById(int id)
 {
     using var Context = new NorthWindContext();
     return(Context.Products.Where(p => p.Id == id).FirstOrDefault());
 }
Exemplo n.º 5
0
 public List <Product> GetAll()
 {
     //no hay que usar el using como llave
     using var Context = new NorthWindContext();
     return(Context.Products.ToList());
 }