示例#1
0
 public List <Product> GetAll(Expression <Func <Product, bool> > filter = null)//parametre lambda olacak
 {
     using (MyDataBaseContext context = new MyDataBaseContext())
     {
         return(filter == null?context.Set <Product>().ToList() : context.Set <Product>().Where(filter).ToList());
     }
     /*filtre null ise direkt listeyi dön, değilse where'e filtreyi ver öyle dön.*/
 }
示例#2
0
 public Product Get(Expression <Func <Product, bool> > filter)//parametre lambda olacak
 {
     using (MyDataBaseContext context = new MyDataBaseContext())
     {
         return(context.Set <Product>().SingleOrDefault(filter));
     }/*Get metodu bize birtane dönecek,default olarak filtresi null değil yani
       * filtre verilmek zorunda. Verilen filteyi uygular ve single or default sayesinde 1 tane döner*/
 }
示例#3
0
 public void Update(Product entity)
 {
     using (MyDataBaseContext context = new MyDataBaseContext())
     {
         var updatedEntity = context.Entry(entity);
         updatedEntity.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
示例#4
0
 public void Delete(Product entity)
 {
     using (MyDataBaseContext context = new MyDataBaseContext())
     {
         var deletedEntity = context.Entry(entity);
         deletedEntity.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
示例#5
0
 public void Add(Product entity)
 {
     using (MyDataBaseContext context = new MyDataBaseContext())
     {
         var addedEntity = context.Entry(entity);
         addedEntity.State = EntityState.Added;
         context.SaveChanges();
     }
 }