예제 #1
0
        //DatabaseDTO Database { set; get; }
        public void ConvertRelationship(RelationshipDTO relationship, Enum_RelationshipType targetRaltionshipType)
        {
            ModelDataHelper dataHelper       = new ModelDataHelper();
            var             relationshinInfo = dataHelper.GetRelationshipsInfoWithEntityIds(MyProjectManager.GetMyProjectManager.GetRequester(), relationship);

            if (relationship.TypeEnum == Enum_RelationshipType.OneToMany ||
                targetRaltionshipType == Enum_RelationshipType.ManyToOne)
            {
                if (relationshinInfo.FKHasData == true && relationshinInfo.MoreThanOneFkForEachPK == true)
                {
                    throw new Exception("بعلت وجود ارتباط یک به چند بین داده های دو جدول امکان تبدیل وجود ندارد");
                }
            }

            if (targetRaltionshipType == Enum_RelationshipType.OneToMany ||
                targetRaltionshipType == Enum_RelationshipType.ManyToOne ||
                targetRaltionshipType == Enum_RelationshipType.ImplicitOneToOne ||
                targetRaltionshipType == Enum_RelationshipType.ExplicitOneToOne
                )
            {
                bizRelationship.ConvertRelationship(MyProjectManager.GetMyProjectManager.GetRequester(), relationship, targetRaltionshipType);
            }
            else if (targetRaltionshipType == Enum_RelationshipType.SuperToSub)
            {
                // OneToMany , ImplicitOneToOne , UnionToSubUnion_SubUnionHoldsKeys , SubUnionToUnion_UnionHoldsKeys
                var isaRelationships = bizISARelationship.GetISARelationshipsByEntityID(relationship.EntityID1);
                ISARelationshipCreateOrSelect(isaRelationships, relationship, targetRaltionshipType);
            }
            else if (targetRaltionshipType == Enum_RelationshipType.SubToSuper)
            {
                // ManyToOne , ExplicitOneToOne , UnionToSubUnion_UnionHoldsKeys , SubUnionToUnion_SubUnionHoldsKeys
                var isaRelationships = bizISARelationship.GetISARelationshipsByEntityID(relationship.EntityID2);
                ISARelationshipCreateOrSelect(isaRelationships, relationship, targetRaltionshipType);
            }
            else if (targetRaltionshipType == Enum_RelationshipType.SubUnionToUnion)
            {
                // OneToMany , ImplicitOneToOne , SuperToSub , UnionToSubUnion_SubUnionHoldsKeys
                var unionRelationships = bizUnionRelationship.GetUnionRelationshipsBySuperUnionEntity(relationship.EntityID2, true);
                UnionRelationshipCreateOrSelect(unionRelationships, true, relationship, targetRaltionshipType);
            }
            //else if (targetRaltionshipType == Enum_RelationshipType.SubUnionToUnion_SubUnionHoldsKeys)
            //{
            //    // ManyToOne , ExplicitOneToOne , SuperToSub , UnionToSubUnion_UnionHoldsKeys
            //    var unionRelationships = bizUnionRelationship.GetUnionRelationshipsBySuperUnionEntity(relationship.EntityID2, false);
            //    UnionRelationshipCreateOrSelect(unionRelationships, false, relationship, targetRaltionshipType);
            //}
            //else if (targetRaltionshipType == Enum_RelationshipType.UnionToSubUnion_SubUnionHoldsKeys)
            //{
            //    // OneToMany , ImplicitOneToOne , SuperToSub , SubUnionToUnion_UnionHoldsKeys
            //    var unionRelationships = bizUnionRelationship.GetUnionRelationshipsBySuperUnionEntity(relationship.EntityID1, true);
            //    UnionRelationshipCreateOrSelect(unionRelationships, true, relationship, targetRaltionshipType);
            //}
            else if (targetRaltionshipType == Enum_RelationshipType.UnionToSubUnion)
            {
                // ManyToOne , ExplicitOneToOne , SuperToSub , SubUnionToUnion_SubUnionHoldsKeys
                var unionRelationships = bizUnionRelationship.GetUnionRelationshipsBySuperUnionEntity(relationship.EntityID1, false);
                UnionRelationshipCreateOrSelect(unionRelationships, false, relationship, targetRaltionshipType);
            }

            //else if (relationship.TypeEnum == Enum_RelationshipType.ManyToOne)
            //{
            //    if (bizRelationship.RelationshipHasManyData(relationship))
            //    {
            //        throw new Exception("بعلت وجود ارتباط یک به چند بین داده های دو جدول امکان تبدیل وجود ندارد");
            //    }
            //    if (targetRaltionshipType == Enum_RelationshipType.ExplicitOneToOne)
            //        bizRelationship.ConvertManyToOneToExplicit(relationship);
            //    else if (targetRaltionshipType == Enum_RelationshipType.SubToSuper)
            //    {
            //        var isaRelationships = bizISARelationship.GetISARelationships(relationship.EntityID2);
            //        ISARelationshipCreateOrSelect(isaRelationships, relationship, targetRaltionshipType);
            //    }
            //    else if (targetRaltionshipType == Enum_RelationshipType.UnionToSubUnion_UnionHoldsKeys)
            //    {
            //        var unionRelationships = bizUnionRelationship.GetUnionRelationships(relationship.EntityID1, true);
            //        UnionRelationshipCreateOrSelect(unionRelationships, true, relationship, targetRaltionshipType);
            //    }
            //    else if (targetRaltionshipType == Enum_RelationshipType.SubUnionToUnion_SubUnionHoldsKeys)
            //    {
            //        var unionRelationships = bizUnionRelationship.GetUnionRelationships(relationship.EntityID1, false);
            //        UnionRelationshipCreateOrSelect(unionRelationships, false, relationship, targetRaltionshipType);
            //    }

            //}
        }