Clear Method problem(?)

Posts   
 
    
Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 20-Jun-2007 23:58:00   

Hi,

I'm have a problem with this.

    Public Shared Function GetAllHpFieldsByHpDataSet(ByVal hpDataSet As HpDataSetEntity) As EntityCollection(Of HpFieldEntity)

        Using Adapter As New DataAccessAdapter
            Dim HoldCollection As EntityCollection(Of HpFieldEntity) = hpDataSet.HpField

            HoldCollection.Clear() ' Clears out existing entities.

            Dim PrefetchPath As IPrefetchPath2 = New PrefetchPath2(EntityType.HpFieldEntity)
            PrefetchPath.Add(HpFieldEntity.PrefetchPathHpCalculatedField)

            Adapter.FetchEntityCollection(HoldCollection, hpDataSet.GetRelationInfoHpField, PrefetchPath)

            Return HoldCollection
        End Using

    End Function

The code works but the HoldCollection.Clear() method takes a long time to execute for the subsequent calls using the same HpDataSetEntity. If I go to a different HpDataSetEntity then the method runs quickly.

I found out that the Clear methods executes the SetRelatedEntity and UnSetRelatedEntity methods in the HpFieldEntity code over 100 times.

Why does it do this and is there a way to accomplish the same thing without have to use the Clear method. The only reason why I use the Clear method is because if I don't, I get duplicate information. in my prefetch path.

Thanks,

Fishy

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 21-Jun-2007 03:42:37   

Hi Fishy. Just to be sure.. What LLBLGen version and RuntimeLibraries are you using?

David Elizondo | LLBLGen Support Team
Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 21-Jun-2007 16:20:46   

I'm using the following:

  • .Net 2.0, VisualStudio 2005

  • LLBLGenPro 2.0.0.0 Final (March 21st, 2007)

  • Code generation: Adapter/VB.Net 2.0/Standard Templates and BackwordsCompatability.Net20

  • LLBLGenPro Lib v2.0.50727

  • Database: SQL Server 2005

Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 21-Jun-2007 17:11:02   

I finally have it working so that it does not take forever to clear out the llbl entities using this code:

    Public Function LoadForms(ByVal application As ApplicationEntity) As EntityCollection(Of FormEntity)

        Using Adapter As New DataAccessAdapter
            For Each frm As FormEntity In application.Form
                frm.FormTrait.Clear()
            Next

            Dim prefetchPath As IPrefetchPath2 = New PrefetchPath2(LLBL.EntityType.FormEntity)
            prefetchPath.Add(FormEntity.PrefetchPathFormTrait)

            Adapter.FetchEntityCollection(application.Form, application.GetRelationInfoForm, prefetchPath)

            Return application.Form
        End Using

    End Function

So, instead of application.Form.Items.Clear, I go through each FormEntity and Clear the FormTrait Collection.

I don't know why I even have to clear the collection at all but if I don't, I have duplicate FormTraitEntities confused

So, even though I've somewhat resolve the problem, I would still like answers to why I have to do it at all and why when I Clear at the Form level it locks up for a long period of time.

Thanks,

Fishy

Edit: I just noticed that the code I just posted was using diffent tables then the original code. It is still basically the same problem and solution. I'll apply my solution to the original problem and let you know if it works. Sorry about that.

Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 21-Jun-2007 17:32:30   

Yes. It does work.