예제 #1
0
 public Car Get(Expression <Func <Car, bool> > filter)
 {
     using (CarProjectDbContext context = new CarProjectDbContext())
     {
         return(context.Set <Car>().SingleOrDefault(filter));
     }
 }
예제 #2
0
 public void Update(Car entity)
 {
     using (CarProjectDbContext context = new CarProjectDbContext())
     {
         var updatedEntity = context.Entry(entity);
         updatedEntity.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #3
0
 public List <Car> GetAll(Expression <Func <Car, bool> > filter = null)
 {
     using (CarProjectDbContext context = new CarProjectDbContext())
     {
         return(filter == null
             ? context.Set <Car>().ToList()
             : context.Set <Car>().Where(filter).ToList());
     }
 }
예제 #4
0
 public void Delete(Car entity)
 {
     using (CarProjectDbContext context = new CarProjectDbContext())
     {
         var deletedEntity = context.Entry(entity);
         deletedEntity.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
예제 #5
0
 public void Add(Car entity)
 {
     //using = IDisposable pattern implemantation of c#
     using (CarProjectDbContext context = new CarProjectDbContext())
     {
         var addedEntity = context.Entry(entity);
         addedEntity.State = EntityState.Added;
         context.SaveChanges();
     }
 }