In post #4071 you talk about dropping the ObjectAlias from the IEntityField2 implementation for speed/space and I think I was relying on this.
What I'm doing is constructing a search screen that allows the user to type in one or more (up to ~20) pieces of information to find what they're looking for. Depending on the data supplied different tables are required. Rather than putting a lot of dependencies between the fields that can be supplied I just add all relationships individually to a relationshipBucket and then iterate through that bucket checking to ensure that the relationship isn't already in the TypedList relations and hasn't been added already. This all works ok except for the one case where I want to add a duplicate relationship with a different alias.
My code is something like (actual code below):
for each relation in the existing collection:
determine whether a match exists by checking the first field (I only have single field primary keys) of relation.GetAllPKEntityFieldCoreObjects for matches on:
field.ContainingObjectname
field.Name
field.ObjectAlias
if the PK matches do the same check for the first field from realtion.GetAllFKEntityFieldCoreObjects
if the FK and the PK don't match add the relation to the existing collection
The trouble is that the ObjectAlias is always String.Empty and so a false match is made.
Is there any other way I can do this?
Using:
- Adapter
- .NET 1.1
- LLBL 1.0.20042.50729
pkParamArrayList = newRelation.GetAllPKEntityFieldCoreObjects
fkParamArrayList = newRelation.GetAllFKEntityFieldCoreObjects
For Each filterRelation As EntityRelation In existingRelationCollection
PKRelationExists = True
FKRelationExists = True
pkFilterArrayList = filterRelation.GetAllPKEntityFieldCoreObjects
fkFilterArrayList = filterRelation.GetAllFKEntityFieldCoreObjects
Dim existingPKField As IEntityField2 = CType(pkFilterArrayList(0), EntityField2)
Dim newPKField As IEntityField2 = CType(pkParamArrayList(0), EntityField2)
If existingPKField.ContainingObjectName = newPKField.ContainingObjectName _
AndAlso existingPKField.Name = newPKField.Name _
AndAlso existingPKField.ObjectAlias = newPKField.ObjectAlias Then
PKRelationExists = True
Else
PKRelationExists = False
End If
Dim existingFKField As IEntityField2 = CType(fkFilterArrayList(0), EntityField2)
Dim newFKField As IEntityField2 = CType(fkParamArrayList(0), EntityField2)
If existingFKField.ContainingObjectName = newFKField.ContainingObjectName _
AndAlso existingFKField.Name = newFKField.Name _
AndAlso existingFKField.ObjectAlias = newFKField.ObjectAlias Then
FKRelationExists = True
Else
FKRelationExists = False
End If
RelationExists = PKRelationExists And FKRelationExists
If RelationExists Then
Exit For
End If
Next
If Not RelationExists Then
existingRelationCollection.Add(newRelation, newRelation.AliasPKSide, newRelation.AliasFKSide, newRelation.HintForJoins)
End If