Hi John -
Perhaps this will help you. Using this method, you can determine whether or not the RelationCollection already contains the Relation you are about to add.
Public Shared Function RelationsMatch(ByVal myRelation1 As IEntityRelation, ByVal myRelation2 As IEntityRelation) As Boolean
Dim isIdentical As Boolean = True
isIdentical = isIdentical And myRelation1.GetPKEntityFieldCore(0).ContainingObjectName = myRelation2.GetPKEntityFieldCore(0).ContainingObjectName
isIdentical = isIdentical And myRelation1.GetFKEntityFieldCore(0).ContainingObjectName = myRelation2.GetFKEntityFieldCore(0).ContainingObjectName
isIdentical = isIdentical And myRelation1.GetPKEntityFieldCore(0).ActualContainingObjectName = myRelation2.GetPKEntityFieldCore(0).ActualContainingObjectName
isIdentical = isIdentical And myRelation1.GetFKEntityFieldCore(0).ActualContainingObjectName = myRelation2.GetFKEntityFieldCore(0).ActualContainingObjectName
isIdentical = isIdentical And myRelation1.AliasEndEntity = myRelation2.AliasEndEntity
isIdentical = isIdentical And myRelation1.AliasFKSide = myRelation2.AliasFKSide
isIdentical = isIdentical And myRelation1.AliasLeftOperand = myRelation2.AliasLeftOperand
isIdentical = isIdentical And myRelation1.AliasPKSide = myRelation2.AliasPKSide
isIdentical = isIdentical And myRelation1.AliasRightOperand = myRelation2.AliasRightOperand
isIdentical = isIdentical And myRelation1.AliasStartEntity = myRelation2.AliasStartEntity
isIdentical = isIdentical And myRelation1.AmountFields = myRelation2.AmountFields
'isIdentical = isIdentical And myRelation1.CustomFilter = myRelation2.CustomFilter
isIdentical = isIdentical And myRelation1.CustomFilterReplacesOnClause = myRelation2.CustomFilterReplacesOnClause
isIdentical = isIdentical And myRelation1.HintForJoins = myRelation2.HintForJoins
'isIdentical = isIdentical And myRelation1.InheritanceInfoFkSideEntity = myRelation2.InheritanceInfoFkSideEntity
'isIdentical = isIdentical And myRelation1.InheritanceInfoPkSideEntity = myRelation2.InheritanceInfoPkSideEntity
isIdentical = isIdentical And myRelation1.IsHierarchyRelation = myRelation2.IsHierarchyRelation
isIdentical = isIdentical And myRelation1.IsWeak = myRelation2.IsWeak
isIdentical = isIdentical And myRelation1.JoinType = myRelation2.JoinType
'isIdentical = isIdentical And myRelation1.LeftOperandInheritanceInfo = myRelation2.LeftOperandInheritanceInfo
isIdentical = isIdentical And myRelation1.MappedFieldName = myRelation2.MappedFieldName
'isIdentical = isIdentical And myRelation1.RightOperandInheritanceInfo = myRelation2.RightOperandInheritanceInfo
isIdentical = isIdentical And myRelation1.StartElementIsPkSide = myRelation2.StartElementIsPkSide
isIdentical = isIdentical And myRelation1.StartEntityIsPkSide = myRelation2.StartEntityIsPkSide
isIdentical = isIdentical And myRelation1.TypeOfRelation = myRelation2.TypeOfRelation
Return isIdentical
End Function
Hope this helps!
Ryan