コード例 #1
0
 public override void ElementDeleting(Microsoft.VisualStudio.Modeling.ElementDeletingEventArgs e)
 {
     ORMSolutions.ORMArchitect.Framework.Diagnostics.TraceUtility.TraceRuleStart(e.ModelElement.Store, "ORMSolutions.ORMArchitect.RelationalModels.ConceptualDatabase.ReferenceConstraint.UniquenessConstraintColumnDeleting");
     ReferenceConstraint.UniquenessConstraintColumnDeleting(e);
     ORMSolutions.ORMArchitect.Framework.Diagnostics.TraceUtility.TraceRuleEnd(e.ModelElement.Store, "ORMSolutions.ORMArchitect.RelationalModels.ConceptualDatabase.ReferenceConstraint.UniquenessConstraintColumnDeleting");
 }
コード例 #2
0
 public override void RolePlayerPositionChanged(Microsoft.VisualStudio.Modeling.RolePlayerOrderChangedEventArgs e)
 {
     ORMSolutions.ORMArchitect.Framework.Diagnostics.TraceUtility.TraceRuleStart(e.SourceElement.Store, "ORMSolutions.ORMArchitect.RelationalModels.ConceptualDatabase.ReferenceConstraint.UniquenessConstraintColumnPositionChanged");
     ReferenceConstraint.UniquenessConstraintColumnPositionChanged(e);
     ORMSolutions.ORMArchitect.Framework.Diagnostics.TraceUtility.TraceRuleEnd(e.SourceElement.Store, "ORMSolutions.ORMArchitect.RelationalModels.ConceptualDatabase.ReferenceConstraint.UniquenessConstraintColumnPositionChanged");
 }
コード例 #3
0
ファイル: ReferenceConstraint.cs プロジェクト: ozialien/NORMA
        private static void ValidateTargetUniquenessConstraint(ReferenceConstraintTargetsTable tableReference, INotifyElementAdded notifyAdded)
        {
            if (tableReference.IsDeleted)
            {
                return;
            }
            Table targetTable = tableReference.TargetTable;
            ReferenceConstraint referenceConstraint = tableReference.ReferenceConstraint;
            LinkedElementCollection <ColumnReference> columnRefs = referenceConstraint.ColumnReferenceCollection;
            int columnRefCount = columnRefs.Count;
            ReferenceConstraintTargetsUniquenessConstraint targetUniquenessLink = ReferenceConstraintTargetsUniquenessConstraint.GetLinkToTargetUniquenessConstraint(referenceConstraint);

            if (targetUniquenessLink != null)
            {
                // Verify the target uniqueness
                UniquenessConstraint targetUniqueness = targetUniquenessLink.TargetUniquenessConstraint;
                bool existingIsValid = targetUniqueness.Table == targetTable;
                if (existingIsValid)
                {
                    LinkedElementCollection <Column> uniquenessColumns = targetUniqueness.ColumnCollection;
                    existingIsValid = uniquenessColumns.Count == columnRefCount;
                    if (existingIsValid)
                    {
                        for (int i = 0; i < columnRefCount; ++i)
                        {
                            if (uniquenessColumns[i] != columnRefs[i].TargetColumn)
                            {
                                existingIsValid = false;
                                break;
                            }
                        }
                    }
                }
                if (!existingIsValid)
                {
                    // Delete the link without deleting the reference constraint we're processing
                    targetUniquenessLink.Delete(ReferenceConstraintTargetsUniquenessConstraint.ReferenceConstraintDomainRoleId);
                    targetUniquenessLink = null;
                }
            }
            if (targetUniquenessLink == null)
            {
                foreach (UniquenessConstraint testUniqueness in targetTable.UniquenessConstraintCollection)
                {
                    LinkedElementCollection <Column> uniquenessColumns = testUniqueness.ColumnCollection;
                    if (uniquenessColumns.Count == columnRefCount)
                    {
                        int i = 0;
                        for (; i < columnRefCount; ++i)
                        {
                            if (uniquenessColumns[i] != columnRefs[i].TargetColumn)
                            {
                                break;
                            }
                        }
                        if (i == columnRefCount)
                        {
                            // We have a match
                            targetUniquenessLink = new ReferenceConstraintTargetsUniquenessConstraint(referenceConstraint, testUniqueness);
                            if (notifyAdded != null)
                            {
                                notifyAdded.ElementAdded(targetUniquenessLink, false);
                            }
                            break;
                        }
                    }
                }
                if (targetUniquenessLink == null)
                {
                    referenceConstraint.Delete();
                }
            }
        }