protected object SetDaoInstancePropertiesAndSave(object poco, Dao daoInstance) { Meta.SetUuid(poco); Meta.SetCuid(poco); daoInstance.CopyProperties(poco); daoInstance.Property("Database", Database); Type pocoType = GetBaseType(poco.GetType()); SaveDaoInstance(pocoType, daoInstance); bool saveAgain = false; if (SetChildDaoCollectionValues(poco, daoInstance)) { saveAgain = true; } if (SetXrefDaoCollectionValues(poco, daoInstance)) { saveAgain = true; } if (saveAgain) { daoInstance.ForceUpdate = true; SaveDaoInstance(pocoType, daoInstance); } object wrapper = ConstructWrapper(pocoType); wrapper.CopyProperties(daoInstance); poco.CopyProperties(wrapper); return(wrapper); }
protected void SetMeta(object instance) { if (RequireUuid) { Meta.SetUuid(instance); } if (RequireCuid) { Meta.SetCuid(instance); } }
private void SetXrefDaoCollectionValues(object pocoOrPocoParent, Dao daoInstance, PropertyInfo daoXrefProperty, PropertyInfo pocoProperty) { IEnumerable values = (IEnumerable)pocoProperty.GetValue(pocoOrPocoParent); if (values != null) { IAddable xrefDaoCollection = (IAddable)daoXrefProperty.GetValue(daoInstance); foreach (object o in values) { Meta.SetUuid(o); Meta.SetCuid(o); Dao dao = GetDaoType(o.GetType()).Construct <Dao>(); dao.CopyProperties(o); xrefDaoCollection.Add(dao); } } }
public bool SetChildDaoCollectionValues(object poco, Dao daoInstance) { List <TypeFk> fkDescriptors = TypeSchema.ForeignKeys.Where(tfk => tfk.PrimaryKeyType == GetBaseType(poco.GetType())).ToList(); bool result = false; foreach (TypeFk fkDescriptor in fkDescriptors) { PropertyInfo childCollectionDaoProperty = GetChildCollectionDaoPropertyForTypeFk(fkDescriptor); IEnumerable values = (IEnumerable)fkDescriptor.CollectionProperty.GetValue(poco) ?? new object[] { }; IAddable daoCollection = (IAddable)childCollectionDaoProperty.GetValue(daoInstance); foreach (object o in values) { Meta.SetUuid(o); Meta.SetCuid(o); Dao dao = GetDaoType(GetBaseType(o.GetType())).Construct <Dao>(); dao.CopyProperties(o); daoCollection.Add(dao); result = true; } } return(result); }