コード例 #1
0
        public void Add(CslaObjectInfo mainObject)
        {
            if (RelationRulesEngine.IsAllowedEntityObject(mainObject))
            {
                var entity = new AssociativeEntity(GeneratorController.Current.CurrentUnit);
                entity.RelationType      = ObjectRelationType.OneToMultiple;
                entity.ObjectName        = mainObject.ObjectName;
                entity.MainObject        = mainObject.ObjectName;
                entity.MainLazyLoad      = false;
                entity.SecondaryLazyLoad = false;

                var mainCriteriaInfo    = typeof(CslaObjectInfo).GetProperty("CriteriaObjects");
                var mainCriteriaObjects = mainCriteriaInfo.GetValue(mainObject, null);
                foreach (var crit in (CriteriaCollection)mainCriteriaObjects)
                {
                    foreach (var prop in crit.Properties)
                    {
                        entity.MainLoadProperties.Add(CriteriaProperty.Clone(prop));
                    }
                }

                Add(entity);
            }
            else
            {
                throw new Exception(mainObject + " isn't a suitable object for this builder.");
            }
        }
コード例 #2
0
        public void Add(CslaObjectInfo mainObject, CslaObjectInfo secondaryObject)
        {
            if (RelationRulesEngine.IsAllowedEntityObject(mainObject))
            {
                if (RelationRulesEngine.IsAllowedEntityObject(secondaryObject))
                {
                    var entity = new AssociativeEntity(GeneratorController.Current.CurrentUnit);
                    entity.RelationType      = ObjectRelationType.ManyToMany;
                    entity.ObjectName        = mainObject.ObjectName + secondaryObject.ObjectName;
                    entity.MainLazyLoad      = false;
                    entity.SecondaryLazyLoad = false;

                    entity.MainObject             = mainObject.ObjectName;
                    entity.MainPropertyName       = secondaryObject.ObjectName + entity.Parent.Params.ORBChildPropertySuffix;
                    entity.MainItemTypeName       = mainObject.ObjectName + secondaryObject.ObjectName;
                    entity.MainCollectionTypeName = entity.MainItemTypeName + entity.Parent.Params.ORBCollectionSuffix;

                    var mainCriteriaInfo    = typeof(CslaObjectInfo).GetProperty("CriteriaObjects");
                    var mainCriteriaObjects = mainCriteriaInfo.GetValue(mainObject, null);
                    foreach (var crit in (CriteriaCollection)mainCriteriaObjects)
                    {
                        foreach (var prop in crit.Properties)
                        {
                            entity.MainLoadProperties.Add(CriteriaProperty.Clone(prop));
                        }
                    }

                    entity.SecondaryObject             = secondaryObject.ObjectName;
                    entity.SecondaryPropertyName       = mainObject.ObjectName + entity.Parent.Params.ORBChildPropertySuffix;
                    entity.SecondaryItemTypeName       = secondaryObject.ObjectName + mainObject.ObjectName;
                    entity.SecondaryCollectionTypeName = entity.SecondaryItemTypeName +
                                                         entity.Parent.Params.ORBCollectionSuffix;

                    var secondaryCriteriaInfo    = typeof(CslaObjectInfo).GetProperty("CriteriaObjects");
                    var secondaryCriteriaObjects = secondaryCriteriaInfo.GetValue(secondaryObject, null);
                    foreach (var crit in (CriteriaCollection)secondaryCriteriaObjects)
                    {
                        foreach (var prop in crit.Properties)
                        {
                            entity.SecondaryLoadProperties.Add(CriteriaProperty.Clone(prop));
                        }
                    }

                    Add(entity);
                }
                else
                {
                    throw new Exception(secondaryObject + " isn't a suitable object for this builder.");
                }
            }
            else
            {
                throw new Exception(mainObject + " isn't a suitable object for this builder.");
            }
        }