EntityField2.ObjectAlias not serialized

Posts   
 
    
Posts: 134
Joined: 04-Mar-2005
# Posted on: 01-Feb-2006 18:28:15   

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

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 02-Feb-2006 11:34:56   

THe alias for the pk/fk side in an entityrelation isn't set on the field object, but in the EntityRelation object itself. (as for all fields in the PK it's the same)

So you should use the EntityRelation.AliasFKSide and AliasPKSide properties instead. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Posts: 134
Joined: 04-Mar-2005
# Posted on: 03-Feb-2006 01:45:28   

If only all my problems could be solved so easily!

Thanks Frans