コード例 #1
0
        public void Update(MT_SellOut entity, params Expression <Func <T, object> >[] updatedProperties)
        {
            using (var ctx = new DemoEntities1())
            {
                ctx.MT_SellOut.Attach(entity);
                var entry = ctx.Entry(entity);
                entry.Property(e => e.Perform).IsModified = true;
                entry.Property(e => e.Rate).IsModified    = true;

                ctx.SaveChanges();
            }
            //if (updatedProperties.Any())
            //{

            //    foreach (var property in updatedProperties)
            //    {

            //        entry.Property(property).IsModified = true;
            //        db.SaveChanges();
            //    }

            //}
            //else
            //{

            //    foreach (var property in entry.OriginalValues.PropertyNames)
            //    {
            //        var original = entry.OriginalValues.GetValue<object>(property);
            //        var current = entry.CurrentValues.GetValue<object>(property);
            //        if (original != null && !original.Equals(current))
            //            entry.Property(property).IsModified = true;
            //    }
            //}
            //var dbEntityEntry = db.Entry(entity);
        }
コード例 #2
0
 public void Update(T entity)
 {
     //table.Attach(entity);
     db.Entry(entity).State = EntityState.Modified;
     db.SaveChanges();
 }