N to 1 relation : out of sync

Posts   
 
    
Guilmo1080
User
Posts: 5
Joined: 04-Aug-2006
# Posted on: 01-Sep-2006 11:19:08   

Hello

I tried to read two table A and B. The table A has a relation N to 1 with the table B. So there was two records of the table A that have a link (FK) with the same record of the table B.

Ex :

Table A ID : 12 FKID : 3 ID : 13 FKID : 3

Table B ID : 3

When i want to load my collection, the second row is out of sync and the error stop the load of the collection. I didn't see how to load this two rows. I want just read any filed of those tables.

my code :


Public Overridable Property [IdAndLibelleRegle]() As System.String

            Get

                'Recuperation de l'id du conteneur valeur simple

                Dim oIdValeurSimple As Object = MyBase.GetCurrentFieldValue(CType(TABLEAFieldIndex.Te3FCdvrdvDId, Integer))

                Dim oCoetbValeurSimple As Object = MyBase.GetCurrentFieldValue(CType(TABLEAFieldIndex.Coetb, Integer))

                Dim idValeurSimple As String = CType(oIdValeurSimple, System.String)

                Dim CoetbValeurSimple As String = CType(oCoetbValeurSimple, System.String)

                Dim adapter As New DataAccessAdapter

                Dim regle As New TABLEBEntity(idValeurSimple, CoetbValeurSimple)

                adapter.FetchEntity(regle)

                adapter.Dispose()

                Return regle.Id + " - " + regle.Libelle

            End Get

            Set(ByVal Value As System.String)

            End Set
        End Property


#Region "Fonction SVR_FT_011 : ChargerRegle"

    ''*************** Fonction XXXXXXX ******************

    '' Load the dropdown list.

    Public Sub ChargerRegle()

        '**********************************************
        'Var
        '**********************************************

        Dim regle As New EntityCollection(New ConteneurValeurSimpleEntityFactory)   ' Collection contenant les règles à afficher
        Dim regleEntity As New ConteneurValeurSimpleEntity
        Dim filter As New RelationPredicateBucket     ' Filter
        Dim adapter As New DataAccessAdapter        ' DataAccessAdapter
        Dim prefetchPath As IPrefetchPath2             ' Link
        Dim typeErreur As New LogErreurType        ' Error
        Dim regleE As New regleEntity



        '***********************************************
        'Init
        '***********************************************

       Try

            adapter.StartTransaction(IsolationLevel.Serializable, "ChargerRegle")

            ' Filtre sur le code établissement de la règle
            filter.PredicateExpression.Add(New FieldCompareValuePredicate( _
                TABLEAFields.Te3FCdvrdvDCoetb, _
                Nothing, _
                ComparisonOperator.Equal, _
                Session.Item("COETB")))

            ' Filtre sur le type de retour de la règle

            filter.PredicateExpression.Add(New FieldCompareValuePredicate( _
                TABLEAFields.Te1ICdvtyvDCode, _
                Nothing, _
                ComparisonOperator.Equal, _
                Session.Item("CodeGroupeType")))

            ' Filtre sur le code établissement de la règle

            filter.PredicateExpression.AddWithAnd(New FieldCompareValuePredicate( _
                ConteneurValeurSimpleFields.Te1ICdvtyvDCoetb, _
                Nothing, _
                ComparisonOperator.Equal, _
                Session.Item("CoetbGroupeType")))

            adapter.FetchEntityCollection(regle, filter)  ' Chargement des données
            regle.SupportsSorting = True    ' Autorisation du code
            regle.Sort(18, ComponentModel.ListSortDirection.Ascending)  ' Tri sur l'ID de la règle

        Catch ex As Exception

            adapter.Dispose()
            clsLogErreur.EcrireLog(Session.Item("nom"), ex.Message, typeErreur.Erreur)

        End Try

        '***********************************************
        'Début
        '***********************************************

        Try

            ddlRegle.DataSource = regle.Items   ' Affectation du DataSource
            ddlRegle.DataTextField = "IdAndLibelleRegle"    ' Charge l'id et le libellé de la règle
            ddlRegle.DataValueField = "Id"  ' Charge l'id de la valeur simple en valeur de la DropDownList
            ddlRegle.DataBind() ' Chargement de la DropDownList

            adapter.Commit()

        Catch ex As Exception
            clsLogErreur.EcrireLog(Session.Item("nom"), ex.Message, typeErreur.Alerte)
        End Try

        '*********************************************
        'Fin
        '*********************************************
    End Sub

#End Region


Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 01-Sep-2006 15:23:39   

I can't relate the posted code to your question, please explain the code, or better post a simple example to re-produce your issue.

Anyway to fetch related entities, either use PrefetchPaths to the related entities in your fetch of the main entity. Or LazyLoading would be enough. (SelfServicing ONLY)

Please refer to the LLBLGen Pro manual for PrefetchPaths and LazyLoading.