示例#1
0
        public void Update(T entity)
        {
            using var context = new ShopContext();
            var updatedEntity = context.Entry(entity);

            updatedEntity.State = EntityState.Modified;
            context.SaveChanges();
        }
示例#2
0
 public void Delete(T entity)
 {
     using (var context = new ShopContext())
     {
         var deletedEntity = context.Entry(entity);
         deletedEntity.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
示例#3
0
 public void Create(T entity)
 {
     using (var context = new ShopContext())
     {
         var addedEntity = context.Entry(entity);
         addedEntity.State = EntityState.Added;
         context.SaveChanges();
     }
 }