示例#1
0
 public Car GetById(Expression <Func <Car, bool> > filter)
 {
     using (RentContext context = new RentContext())
     {
         return(context.Set <Car>().SingleOrDefault(filter));
     }
 }
示例#2
0
 public List <Car> GetAll(Expression <Func <Car, bool> > filter = null)
 {
     using (RentContext context = new RentContext())
     {
         return(filter == null?context.Set <Car>().ToList() : context.Set <Car>().Where(filter).ToList());
     }
 }
示例#3
0
 public void Update(Car entity)
 {
     using (RentContext context = new RentContext())
     {
         var updatedContext = context.Entry(entity);
         updatedContext.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
示例#4
0
 public void Delete(Car entity)
 {
     using (RentContext context = new RentContext())
     {
         var deletedContext = context.Entry(entity);
         deletedContext.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
示例#5
0
 public void Add(Car entity)
 {
     using (RentContext context = new RentContext())
     {
         var addedContext = context.Entry(entity);
         addedContext.State = EntityState.Added;
         context.SaveChanges();
     }
 }