views:

37

answers:

1

I have a form that contains information about a client eg/Title, Name and their Address eg/Town, Country.

I have a class for each table that has a Save method to update the database.

I am thinking of having 2 bindingsources one for client and one for address. The controls will bind to the relevant bindingsource. When the user clicks the save button it will call EndEdit on each bindingsource and then for the CurrentItem call the Save method.

Does that sound a good approach?

A: 

You need to ensure the relation between the classes/tables.

I would make sure you have the appropriate FK constraint defined in your db and then generate Linq2Sql or ADO.Net entity model and bind to that.

After you generate your model, Data>Add new datasource>Object and select the customer object from your entity model.

Make sure you use the dropdown on the datasources tool window to choose 'details' for your customer and the nested address.

drag the customer from the datasources toolwindow to the form.

then drag the address property of the customer from the tool window to the form.

you now have 2 binding sources, one for customer and one for address. the address binding source will use the customer binding source as it's datasource.

you are now covered. edit your form and save.

rolling your own databinding with POCO dtos on a winforms app is just more work than you want to do, especially when the facilities are already provided for you.

Sky Sanders
I couldn't drag anything from the address property to the form. The type in my class is IQueryable so I guess that might be why. What I did do is create a ViewModel of the two classes and drag the information from each class to the form and that did the trick and with only one bindingsource. Thanks
Jon
there you go. I contemplated just saying 'nest your classes and create a datasource from the root' but is hard to tell if that will be of help sometimes. cheers.
Sky Sanders