|
Rosacek
User
Location: CZ
Joined on: 18-Mar-2012 18:02:44
Posted: 133 posts
|
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.
Code: |
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
Support Team
Location: Guatemala City
Joined on: 28-Nov-2005 23:35:24
Posted: 8086 posts
|
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.
|
|
|
Rosacek
User
Location: CZ
Joined on: 18-Mar-2012 18:02:44
Posted: 133 posts
|
Thanks Daelmo, I have the same opinion, just needed confirmation.
|
|
|
|