public static void UpdateModel<T>(T entity, DbContext db) where T : class { db.Set<T>().Attach(entity); foreach (System.Reflection.PropertyInfo p in entity.GetType().GetProperties()) { if (p.GetValue(entity) != null) { db.Entry(entity).Property(p.Name).IsModified = true; } } db.SaveChanges(); }
学习交流群:364976091