Synchronise DB content with the model

Posts   
 
    
Meindert
User
Posts: 63
Joined: 07-Nov-2012
# Posted on: 07-Nov-2012 11:58:56   

We use LLBLGen 3.5 to retrieve data for presentations in datagrid (parent - childs grids). Because of complexity and the philisophy to store as much as code in the database, we call stored procedures to manipulate the data.

Manipulating the data means: - some entities are removed - new entities are created - entities have new values

Real example of the entity where we talk about is een collection of CableRoutingTrackRoutesEntity: prefetchPath = New PrefetchPath2(CInt(EntityType.CableRoutingTrackRoutesEntity)) prefetchPath.Add(CableRoutingTrackRoutesEntity.PrefetchPathCableRoutingGraphEdges) prefetchPath.Add(CableRoutingTrackRoutesEntity.PrefetchPathCableRoutingGraphNodesCollectionViaCableRoutingGraphEdges)

As you can see there are two prefetch collections within entity CableRoutingTrackRoutes called: CableRoutingGraphEdges and CableRoutingGraphNodesCollectionViaCableRoutingGraphEdges.

Questions: - Is a LLBLGen design goal to handle this kind of problems (synchronising data); - With help of a context the newly created entities are added with a (re)fetch, but the deleted ones are still in the collection. How to deal with this? - Changed entities are not updated (synchronised), is there a solution for this; - Before (re)fetch of the entity CableRoutingTrackRoutes we try deleted both prefetched entities, but the ...CollectionVia... could not been cleared, because it is read-only.

Biggest question: How should we use LLBLGen, are we asking to much from this tool (related to the synchonisation issue)?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 07-Nov-2012 18:03:30   

The general rule is to always re-load(refetch) the in-memory graphs/collections when you need to use them.

Caching entities in-memory is not a good idea, as data can always be changed by other users.

So the best practice is to fetch entities when you need them, operate on them, and then flush the memory. Re-fetch again when you need them.

Meindert
User
Posts: 63
Joined: 07-Nov-2012
# Posted on: 08-Nov-2012 08:25:57   

Yes that is the point, because i don't know what the best solution is to refetch?!

Should i first try to empty the prefetched collections? the ...CollectionVia... is not so easy to do so.

Or is there a kind of FORCE refetch, that handles the in memory cleaning and fetch the entity with relations again?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 08-Nov-2012 21:19:25   

You need to ditch the entire graph and refetch it. Usually a "new" will do the job.