private void fixupDetachedEntities(object entity) { foreach (var propInfo in entity.GetType().GetProperties()) { var propValue = _reflectionHelper.GetPropValue(entity, propInfo.Name); if (propValue != null && propValue is IEntity && (this.Entry(propValue).State == EntityState.Detached)) { this.Set(propValue.GetType()).Attach(propValue); } } }