コード例 #1
0
 public Product Get(Expression <Func <Product, bool> > filter)
 {
     using (NortwindContext context = new NortwindContext())
     {
         return(context.Set <Product>().SingleOrDefault(filter));
     }
 }
コード例 #2
0
 public List <Product> GetAll(Expression <Func <Product, bool> > filter = null)
 {
     using (NortwindContext context = new NortwindContext())
     {
         return(filter == null?context.Set <Product>().ToList() : context.Set <Product>().Where(filter).ToList());
     }
 }
コード例 #3
0
 public void Update(Product entity)
 {
     using (NortwindContext context = new NortwindContext())
     {
         var updatedEntity = context.Entry(entity);
         updatedEntity.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #4
0
 public List <Product> GetAll(Expression <Func <Product, bool> > filter = null)
 {
     using (NortwindContext context = new NortwindContext())
     {
         return(filter == null
             ? context.Set <Product>().ToList()
             : context.Set <Product>().Where(filter).ToList()); //null sa Select * from products gibi değilse filtreye göre getir
     }
 }
コード例 #5
0
 public void Delete(Product entity)
 {
     using (NortwindContext context = new NortwindContext())
     {
         var deletedEntity = context.Entry(entity);
         deletedEntity.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
コード例 #6
0
 public void Add(Product entity)
 {
     using (NortwindContext context = new NortwindContext())
     {
         var addedEntity = context.Entry(entity);
         addedEntity.State = EntityState.Added;
         context.SaveChanges();
     }
 }
コード例 #7
0
 public void Add(Product entity)
 {
     //IDisponsible pattern implementation of  c#
     using (NortwindContext context = new NortwindContext())
     {
         var addedEntity = context.Entry(entity);
         addedEntity.State = EntityState.Added;
         context.SaveChanges();
     }
 }
コード例 #8
0
 public void Add(Product entity)
 {
     //using bittikten sonra garbage cloolector hemen bellekten siler
     //IDispossable patterne implementation od c#
     using (NortwindContext context = new NortwindContext())
     {
         var addedEntity = context.Entry(entity);
         addedEntity.State = EntityState.Added;
         context.SaveChanges();
     }
 }