TypedLists and entity update

Posts   
 
    
KelMan
User
Posts: 11
Joined: 25-Oct-2006
# Posted on: 12-Apr-2007 21:09:36   

Here is what I’m trying to do:

I've got a classic form with two grids; say a left grid and a right grid. The left contains all the items of a collection and the right one, a subset of the left, all items with a specific property set to true. Between these two grids are buttons that "move" items from the left to the right and vice versa.

Now, these items come from a TypedList as I want to be able to see simultaneously all the related fields of each entity in one row. When I press the "move" button, for each selected row of the left grid I instantiate a new entity, set the IsNew property to true, set the property in question to true and I save the entity (option 2 on "Modifying an entity" - Adapter). Then, I re-fetch the typed list and the items appear on the right grid.

So, my concerns are: Is this the optimal way of doing all that? Is there a way to not use a TypedList, as it is not updatable? To overcome this, I have to update the datastore in order to see the changes. That means that I can’t implement an OK, Cancel form logic. If for example the typed list was updatable, I would have been able to make all the changes in memory and then commit them or discard them with the OK and Cancel buttons.

Thanx, Manos

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 13-Apr-2007 11:05:19   

Is this the optimal way of doing all that?

Yes it is, unless you wanted to commit the changes later.

Is there a way to not use a TypedList, as it is not updatable? To overcome this, I have to update the datastore in order to see the changes. That means that I can’t implement an OK, Cancel form logic.

TypedLists are DataTables, so you can manually add rows to the dataTable. And if you can keep track to those changes, you can later commit them to the database using the same technique you have used before, but thus time you may use an entityCollection instead of an entity.

Also you can use EntityCollections instead of TypedLists, with fields from related tables be mapped as "Fields on related fields".

KelMan
User
Posts: 11
Joined: 25-Oct-2006
# Posted on: 13-Apr-2007 14:12:43   

Walaa wrote:

Is this the optimal way of doing all that?

Yes it is, unless you wanted to commit the changes later.

Yes, I prefer to commit the changes all-together when the user decides to press the OK button

Walaa wrote:

Also you can use EntityCollections instead of TypedLists, with fields from related tables be mapped as "Fields on related fields".

Hmmm... By using a TypedList I can produce a flat table out of a three table hierarchy (Master-Details-Details of Detail). Is this possible using the "Fields on related fields" technique? I've seen that on the "Fields mapped on related fields" tab, I can only define such fields when exist on an immediate related table...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 13-Apr-2007 19:01:07   

you can create master-detail using fields mapped onto related entities, but not deeper.

Another way of doing what you're doing is simply removing all rows and then re-inserting them in one go when you click OK.

Frans Bouma | Lead developer LLBLGen Pro
KelMan
User
Posts: 11
Joined: 25-Oct-2006
# Posted on: 06-May-2007 17:28:11   

I've managed to come up with an elegant solution...

I now use one TypedList that I bind onto two grids using two BindingSources. When the "move" event fires, I set the appropriate flag-field and the Filter property of the second BindingSource to filter out all the entities with flag-field to off.

Now, here comes the tricky part: You can do all that using a DataTable as Datasource but you can't when you use an EntityCollection! That is because the DataTable has a DataView in contrast to EntityCollection that doesn't. The DataView provides advanced filtering and sorting, so what you really need is IBindingList support for the TypedList (the IBindingList is implemented in the DataView).

Just as I was about to get dirty and start implementing the IBindingList , I found that this has been done already! You can get it here: http://www.teamjohnston.net/Downloads.aspx. and find all the implementation details here: http://www.teamjohnston.net/cs/blogs/jesse/default,month,2006-10.aspx#aba0e393e-be64-44c1-9428-1008ea3d8a05

Now, all I have to do is populate the TypedList, then I define two separate ObjectListView objects on that TypedList and then I set these ObjectListViews as datasources. This implementation allows me to update the data store at the end, when the user presses the ok button.