コード例 #1
0
        public void Build()
        {
            if (string.IsNullOrEmpty(_validationError))
            {
                // display start up message to the user
                var sb = new StringBuilder();
                sb.AppendFormat("Starting the build of {0} relation.\r\n", ObjectName);
                OutputWindow.Current.AddOutputInfo(sb.ToString());

                if (MainLoadingScheme == LoadingScheme.ParentLoad)
                {
                    MainLoadProperties.Clear();
                }
                if (SecondaryLoadingScheme == LoadingScheme.ParentLoad)
                {
                    SecondaryLoadProperties.Clear();
                }

                if (RelationType == ObjectRelationType.OneToMany)
                {
                    var factory = new ObjectRelationsFactory(Parent, this);

                    factory.FacadeObjectInfo             = factory.MainObjectInfo;
                    factory.FacadeRootCriteriaProperties = CriteriaPropertyCollection.Clone(factory.MainRootCriteriaProperties);
                    factory.BuildRelationObjects(new EntityFacade(Parent, RelationType, MainObject,
                                                                  MainPropertyName, MainCollectionTypeName,
                                                                  MainItemTypeName, MainLoadingScheme,
                                                                  MainLoadProperties, MainLoadParameters, MainLazyLoad));
                    factory.PopulateRelationObjects(MainItemTypeName, factory.MainRootCriteriaProperties);
                }
                else
                {
                    var factory = new ObjectRelationsFactory(Parent, this);

                    factory.FacadeObjectInfo             = factory.MainObjectInfo;
                    factory.FacadeRootCriteriaProperties = CriteriaPropertyCollection.Clone(factory.MainRootCriteriaProperties);
                    factory.BuildRelationObjects(new EntityFacade(Parent, RelationType, MainObject,
                                                                  MainPropertyName, MainCollectionTypeName,
                                                                  MainItemTypeName, MainLoadingScheme,
                                                                  MainLoadProperties, MainLoadParameters, MainLazyLoad));

                    factory.FacadeObjectInfo             = factory.SecondaryObjectInfo;
                    factory.FacadeRootCriteriaProperties = CriteriaPropertyCollection.Clone(factory.SecondaryRootCriteriaProperties);
                    factory.BuildRelationObjects(new EntityFacade(Parent, RelationType, SecondaryObject,
                                                                  SecondaryPropertyName, SecondaryCollectionTypeName,
                                                                  SecondaryItemTypeName, SecondaryLoadingScheme,
                                                                  SecondaryLoadProperties, SecondaryLoadParameters,
                                                                  SecondaryLazyLoad));

                    factory.PopulateRelationObjects(MainItemTypeName, factory.MainRootCriteriaProperties);
                    factory.PopulateRelationObjects(SecondaryItemTypeName, factory.SecondaryRootCriteriaProperties);
                }

                // display end message to the user
                sb = new StringBuilder();
                sb.AppendFormat("Relation build end.\r\n");
                OutputWindow.Current.AddOutputInfo(sb.ToString());
            }
        }
コード例 #2
0
        private void ValidManyToMany()
        {
            ValidOneToMany();

            var secondaryCslaObject           = _cslaObjects.Find(SecondaryObject);
            var secondaryCslaObjectCollection = _cslaObjects.Find(SecondaryCollectionTypeName);
            var secondaryCslaObjectItem       = _cslaObjects.Find(SecondaryItemTypeName);

            if (secondaryCslaObject == null)
            {
                _validationError += "Secondary Object not found." + Environment.NewLine;
            }
            else if (!RelationRulesEngine.IsAllowedEntityObject(secondaryCslaObject))
            {
                _validationError += SecondaryObject + " isn't allowed to be Secondary Object." + Environment.NewLine;
            }

            if (secondaryCslaObjectCollection == null)
            {
                if (string.IsNullOrEmpty(SecondaryCollectionTypeName))
                {
                    _validationError += "Secondary Collection must be filled." + Environment.NewLine;
                }
            }
            else if (!RelationRulesEngine.IsAllowedEntityCollection(secondaryCslaObjectCollection))
            {
                _validationError += SecondaryCollectionTypeName + " isn't allowed to be Secondary Collection." +
                                    Environment.NewLine;
            }
            else
            {
                _validationError += ValidateLoadingScheme(SecondaryLoadingScheme, SecondaryLazyLoad, "Secondary");
            }

            if (secondaryCslaObjectItem == null)
            {
                if (string.IsNullOrEmpty(SecondaryItemTypeName))
                {
                    _validationError += "Secondary Collection Item must be filled." + Environment.NewLine;
                }
            }
            else if (!RelationRulesEngine.IsAllowedEntityCollectionItem(secondaryCslaObjectItem))
            {
                _validationError += SecondaryItemTypeName + " isn't allowed to be Secondary Collection Item." +
                                    Environment.NewLine;
            }

            if (secondaryCslaObjectCollection != null && secondaryCslaObjectItem != null)
            {
                if (
                    !RelationRulesEngine.IsCompatibleEntityCollectionItemPair(secondaryCslaObjectCollection,
                                                                              secondaryCslaObjectItem))
                {
                    _validationError += SecondaryCollectionTypeName + " Collection is not compatible with " +
                                        SecondaryItemTypeName + " Collection Item." + Environment.NewLine;
                }

                if (!IsChildCorrect(_cslaObjects, SecondaryObject, SecondaryCollectionTypeName))
                {
                    _validationError += SecondaryObject + " must be the parent of " + SecondaryCollectionTypeName + "." +
                                        Environment.NewLine;
                }

                if (!IsChildCorrect(_cslaObjects, SecondaryCollectionTypeName, SecondaryItemTypeName))
                {
                    _validationError += SecondaryCollectionTypeName + " must be the parent of " + SecondaryItemTypeName +
                                        "." + Environment.NewLine;
                }

                if (!IsItemCorrect(_cslaObjects, SecondaryCollectionTypeName, SecondaryItemTypeName))
                {
                    _validationError += SecondaryCollectionTypeName + " item must be " + SecondaryItemTypeName +
                                        "." + Environment.NewLine;
                }
            }

            var mainCslaObject = _cslaObjects.Find(MainObject);

            if (ObjectRelationsFactory.FindAssociativeTable(mainCslaObject, secondaryCslaObject) == null)
            {
                _validationError += "Associative table not found.";
            }
        }