public T Update<T>(T entity) where T : ModelBase { var set = this.Set<T>(); set.Attach(entity); foreach (System.Reflection.PropertyInfo p in entity.GetType().GetProperties()) { if (p.GetValue(entity) != null) { this.Entry<T>(entity).Property(p.Name).IsModified = true; } } this.SaveChanges(); return entity; }
foreach (PropertyInfo p in codeRuleEntity.GetType().GetProperties()) { if (p.GetValue(codeRuleEntity) == null) { db.Entry(codeRuleEntity).Property(p.Name).IsModified = true; } } db.Entry(codeRuleEntity).State = EntityState.Modified;
时间: 2024-10-25 23:25:12