Refetching a Bound EntityCollection

Posts   
 
    
ianbanks
User
Posts: 9
Joined: 21-Sep-2005
# Posted on: 02-Jul-2006 18:47:07   

Hello,

I have an EntityCollection of entities (no prefetch paths) bound to a grid control (A DevExpress XtraGrid).

Every 30 seconds or so the database is polled to check for new entities, deleted entities and modified entities. At the moment the code does:

myEntityCollection.Clear() adapter.FetchEntityCollection(myEntityCollection, ...)

The grid is automatically updated when changes are made to the underlying EntityCollection. The problem is that when the entity collection is cleared, the selected item in the grid is lost (and the first entity is selected again).

Is there any way to:

Refetch the entity collection without clearing it; i.e., fetch the entities and merge new and deleted entities in; or,
Prevent update events from bubbling up to the grid until the entities are refetched.

I currently use a context as well, but that doesn't seem to change the behaviour.

Regards, Ben

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 03-Jul-2006 14:27:05   

I think the point is if you don't clear the entityCollection deleted entities won't get removed from your datagrid.

I think you may save the selected index somewhere and re-select it again after re-loading the entities, which might not be the best solution since a selected item might have different index when reloaded or might have been removed from the new entity collection.

So either leave it as it is, or try to search for the selected entity via its ID/PK and reselect it if it does exist.

ianbanks
User
Posts: 9
Joined: 21-Sep-2005
# Posted on: 03-Jul-2006 16:53:51   

Walaa wrote:

I think the point is if you don't clear the entityCollection deleted entities won't get removed from your datagrid.

I think you may save the selected index somewhere and re-select it again after re-loading the entities, which might not be the best solution since a selected item might have different index when reloaded or might have been removed from the new entity collection.

So either leave it as it is, or try to search for the selected entity via its ID/PK and reselect it if it does exist.

At the moment the DataGrid has no idea when the EntityCollection is going to be updated. The code that refreshes the EntityCollection isn't very close to the grid.

I notice in the following thread that Otis mentioned a feature that might help:

[http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=2365&HighLight=1](http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=2365&HighLight=1)

He says;

"It will change, I don't know when. The current upgrade feature list has a 'refetch graph on existing entity(/ies)' feature planned, so I might be forced to fix it this week in the new code. I filed it as a bug in the bugtracker and I've planned to fix all bugs before the upgrade goes RTM so if it is not a breaking change, I'll probably fix it within a month time."

Did this ever get in to a release? It sounds like it might help.

Regards, Ben

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 04-Jul-2006 02:08:24   

I'm not sure about the update, but the best thing I can tell you to get through your current scenario would be to save the selected row's datakey before the clear and set the selected row to the row with that datakey after the clear. Then you could check if your selected row is the one that was deleted and take the necessary action in that scenario. Of course teh ability to update the collection would be better simple_smile .

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39865
Joined: 17-Aug-2003
# Posted on: 04-Jul-2006 09:02:44   

Refetching an entitycollection with a prefetch path can be done using a context. Pass a context to the fetch method and the prefetch path fetch will be merged into the existing entities.

Frans Bouma | Lead developer LLBLGen Pro