示例#1
0
        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);
        }
示例#2
0
 protected void SetMeta(object instance)
 {
     if (RequireUuid)
     {
         Meta.SetUuid(instance);
     }
     if (RequireCuid)
     {
         Meta.SetCuid(instance);
     }
 }
示例#3
0
        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);
                }
            }
        }
示例#4
0
        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);
        }