Пример #1
0
 public List <Color> GetAll(Expression <Func <Color, bool> > filter = null)
 {
     using (NorthWindContext context = new NorthWindContext())
     {
         return(filter == null?context.Set <Color>().ToList() : context.Set <Color>().Where(filter).ToList());
     }
 }
Пример #2
0
 public Product Get(Expression <Func <Product, bool> > filter)
 {
     using (NorthWindContext context = new NorthWindContext())
     {
         return(context.Set <Product>().SingleOrDefault(filter));
     }
 }
Пример #3
0
 public Color Get(Expression <Func <Color, bool> > filter)
 {
     using (NorthWindContext context = new NorthWindContext())
     {
         return(context.Set <Color>().SingleOrDefault(filter));
     }
 }
Пример #4
0
 public Brand Get(Expression <Func <Brand, bool> > filter)
 {
     using (NorthWindContext context = new NorthWindContext())
     {
         return(context.Set <Brand>().SingleOrDefault(filter));
     }
 }
Пример #5
0
 public void Update(Color entity)
 {
     using (NorthWindContext context = new NorthWindContext())
     {
         var updatedEntity = context.Entry(entity);
         updatedEntity.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Пример #6
0
 public void Delete(Color entity)
 {
     using (NorthWindContext context = new NorthWindContext())
     {
         var deletedEntity = context.Entry(entity);
         deletedEntity.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Пример #7
0
 public void Add(Color entity)
 {
     using (NorthWindContext context = new NorthWindContext())
     {
         var addedEntity = context.Entry(entity);
         addedEntity.State = EntityState.Added;
         context.SaveChanges();
     }
 }
Пример #8
0
 public void Update(Product entity)
 {
     using (NorthWindContext context = new NorthWindContext())
     {
         var updatedEntity = context.Entry(entity);
         updatedEntity.State = Microsoft.EntityFrameworkCore.EntityState.Modified;
         context.SaveChanges();
     }
 }
Пример #9
0
 public void Add(Product entity)
 {
     using (NorthWindContext context = new NorthWindContext())
     {
         var addedEntity = context.Entry(entity);
         addedEntity.State = Microsoft.EntityFrameworkCore.EntityState.Added;
         context.SaveChanges();
     }
 }
Пример #10
0
 public void Add(Product entity)
 {
     //IDisposable pattern implementation of c#
     using (NorthWindContext context = new NorthWindContext())
     {
         var addedEntity = context.Entry(entity);
         addedEntity.State = EntityState.Added;
         context.SaveChanges();
     }
 }
Пример #11
0
 public List <Product> GetAll(Expression <Func <Product, bool> > filter = null)
 {
     using (NorthWindContext context = new NorthWindContext())
     {
         //arka planda select* from products calistirir ve tolist e cevirir
         //filtre olarak gonderecegimiz sey bir lambda
         return(filter == null?context.Set <Product>().ToList()
                    : context.Set <Product>().Where(filter).ToList());
     }
 }
Пример #12
0
 public void Update(Product entity)
 {
     using (NorthWindContext context = new NorthWindContext())
     {
         //git veri kaynagindan gonderdigim productan bir nesneye eslestir ama yeni ekleme oldugu icin direkt ekler
         //bu referansi yakalama
         var updatedEntity = context.Entry(entity);
         //Simdi bu nesneyi napacagiz?
         updatedEntity.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Пример #13
0
 public void Add(Product entity)
 {
     //csharpa ozel biz bi klassi newledigimizede Garbage collector brlli bir zaman sonra duzenli olarak onu atar
     //using icindeki nesneler using bitince aninda garbage collectora derki beni at cunku context nesnesi biraz pahali
     //IDisposable Pattern Implementation of C#
     using (NorthWindContext context = new NorthWindContext())
     {
         //git veri kaynagindan gonderdigim productan bir nesneye eslestir ama yeni ekleme oldugu icin direkt ekler
         //bu referansi yakalama
         var addedEntity = context.Entry(entity);
         //Simdi bu nesneyi napacagiz?
         addedEntity.State = EntityState.Added;
         context.SaveChanges();
     }
 }