views:

38

answers:

2

If you have to retrieve data from a database and bring this dataset to the client, and then allow the user to manipulate the data in various ways before updating the database again, what is a good class design for this if the data tables will not have a 1:1 relationship with the class objects?

Here are some I came up with:

  1. Just manipulate the DataSet itself on the client and then send it back to the database as is. This will work though obviously the code will be very dirty and not well-structured.

  2. Same as #1, but wrap the dataset code around classes. What I mean is that you may have a class that takes a dataset or a datatable in its constructor, and then provides public methods and properties to simplify the code. Inside these methods and properties it will be reading or manipulating the dataset. To update the database afterwards will be easy because you already have the updated dataset.

  3. Get rid of the dataset entirely on the client, convert to objects, then convert back to a dataset when needing to update the database.

Is there any good resources where I can find information on this?

A: 

When i need to model simple things, bring them to memory and manipulate them, i usually create classes that represent each table in the database, that is, table person, class Person.

With some code you can leverage a solution like that, but it is still "dirty". I'm discovering the power of ORM (object-relational mappings) and you can take a look at NHibernate, Fluent Hibernate, among others.

George
A: 

There are tools the do this automatically for you like nHibernate, or entity framework.

the Larger the project is - you better work with classes. (move the data in and our using your own code or one of the tools above)

for small apps you can stay with datasets.

Dani