コード例 #1
0
 public void Update <TEntity>(TEntity entity) where TEntity : class
 {
     using (var context = new RedCarpetDBContext())
     {
         context.Set <TEntity>().Attach(entity);
         context.Entry(entity).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #2
0
        public void UpdateList <TEntity>(IList <TEntity> entities) where TEntity : class
        {
            using (var context = new RedCarpetDBContext())
            {
                foreach (var entity in entities)
                {
                    context.Set <TEntity>().Attach(entity);
                    context.Entry(entity).State = EntityState.Modified;
                }

                context.SaveChanges();
            }
        }