private void _saveExisting(T entity, Entities.Object obj) { foreach (var value in obj.Values) { object attrVal = entity.GetType().GetProperty(value.Attribute.Name)?.GetValue(entity); value.Data = Converter.StringFromObject(attrVal); } _context.SaveChanges(); }
private T _loadObject(Entities.Object obj) { if (obj is null) { return(null); } var entity = Activator.CreateInstance <T>(); entity.Id = obj.Id; foreach (var val in obj.Values) { var prop = entity.GetType().GetProperty(val.Attribute.Name); prop.SetValue(entity, Converter.ObjectFromString(prop.PropertyType, val.Data)); } return(entity); }
private void _saveNew(T entity, Entities.Type type) { var obj = new Entities.Object() { Type = type }; _context.Objects.Add(obj); entity.Id = obj.Id; foreach (var attribute in type.Attributes) { object attrVal = entity.GetType().GetProperty(attribute.Name).GetValue(entity); var value = new Value() { Attribute = attribute, Data = Converter.StringFromObject(attrVal), Object = obj }; _context.Values.Add(value); } _context.SaveChanges(); }