Should Context be cleared before reloading entitycollection from DB?

Posts   
 
    
Rosacek
User
Posts: 155
Joined: 18-Mar-2012
# Posted on: 15-May-2014 15:08:25   

Hi, I use context to have unique entity instance because of prefetch paths.

I am curious what is the best practice when I need to reload entitycollection (added to a context) from DB and a filter is changed between reloads.

For example in the first LoadData call, I want entities having .IsActive=TRUE And then in the second call I want entities having .IsActive=FALSE

If I do not clear myContext, then I will have both active and inactive entities in context. As I use context just to enforce uniqueness, I think, there is not necessary to call myContext.Clear while reloading data.

Public Sub LoadData(filter As IRelationPredicateBucket)
     Using adapter As New DataAccessAdapter
         myContext.Clear '???????? necesary?
         ecol.Clear()
         adapter.FetchEntityCollection(ecol, filter, 0, Nothing, prefetchPath)
     End Using
End Sub
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 16-May-2014 07:48:41   

As I see it, I don't think that you want to clear the Context in this case, you just have to clear the collection, which is done when you re-fetch it. The context keeps the entity instance 'data' in one place when you need to get it or to update it. You clear the Context when you want to reset the instance data control.

David Elizondo | LLBLGen Support Team
Rosacek
User
Posts: 155
Joined: 18-Mar-2012
# Posted on: 16-May-2014 11:23:21   

Thanks Daelmo, I have the same opinion, just needed confirmation.