Click here to Skip to main content
15,894,343 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Database connection Pin
EmZan12-Apr-09 23:36
EmZan12-Apr-09 23:36 
GeneralRe: Database connection Pin
Colin Angus Mackay12-Apr-09 23:52
Colin Angus Mackay12-Apr-09 23:52 
GeneralRe: Database connection Pin
EmZan13-Apr-09 0:05
EmZan13-Apr-09 0:05 
GeneralRe: Database connection Pin
Colin Angus Mackay13-Apr-09 0:14
Colin Angus Mackay13-Apr-09 0:14 
GeneralRe: Database connection Pin
EmZan13-Apr-09 2:11
EmZan13-Apr-09 2:11 
GeneralRe: Database connection Pin
dojohansen14-Apr-09 22:21
dojohansen14-Apr-09 22:21 
GeneralRe: Database connection Pin
Colin Angus Mackay15-Apr-09 0:11
Colin Angus Mackay15-Apr-09 0:11 
GeneralRe: Database connection [modified] Pin
dojohansen15-Apr-09 0:59
dojohansen15-Apr-09 0:59 
We largely agree then. You're definitely right that using a reader and assigning the properties/fields of a class is faster to load than datasets. I just don't think the difference actually matters in all applications.

More importantly, data sets have some very nice features. They lend themselves to AJAX and web services rather well since their internal representation is XML, meaning they serialize and deserialize to and from XML very efficiently. You can save them to files and modify them in disconnected mode, such as on a laptop on the road, and easily sync back to some other store ("the central database") at a later time. You can filter the data and sort it very easily, add relations between entities of data dynamically, verify constraints, cascade deletes, and detect concurrency violations.

All of this is out-of-the-box functionality you get just by using datasets and adapters. If you want to get the same functionality but use your own custom data objects you run into a bunch of other constraints. Of course it is possible to recreate this sort of flexible and rich functionality in your entity objects, but trust me, if you do they will not be as lightweight anymore. To implement things like the DataTable.Select() method or DataViews and filters, or relations, you need to start including metadata in the classes or use reflection to discover it, and you then lose the raw speed of primitive data objects with hardcoded relations, as in obj.Name = reader.GetString("name");. Sometimes this extra speed is necessary or at least highly desireable for an app to do it's job properly, but other times the user wouldn't even be able to tell any difference at all.

So for me, dismissing datasets and adapters isn't a decision to be taken before you've asked yourself - and answered - this question: How much of the functionality it offers is useful to me? How much might become useful down the road?

A specific example where datasets may be an excellent fit: You're writing an AJAX-enabled web app and have this idea: What if we simply use the same schema for the XML data on the wire as that used by the DataSet itself? We can have a client-side component (such as a table with in-place editing capability) effectively perform Insert, Update, Delete operations on the disconnected dataset without having to contact the server at all, neither by postback nor any AJAX callback. The UI would then basically just become a specialized XML editor.

After multiple edits have been made and are ready to be persisted, the client makes an AJAX request the body of which is the edited XML document, and the server simply creates a dataset from the XML and uses DataAdapter.Update() to delete, insert, and update as required, detecting concurrency violations if any.

Personally, I quite like the datasets. I just wish MS had done a better job with the typed datasets, because they completely ruined this functionality just by choosing naming conventions and a use of nested types that means writing ANY amount of code to use the generated stuff makes you cringe. I mean, seriously... it's stuff like this:

AdventureWorksDataSet.HumanResources_EmployeeTableRow r = AdventureWorksDS.HumanResources_EmployeeTable.NewHumanResources_EmployeeTableRow();

where it should have been
Employee e = DS.Employee.CreateNew();


For clarity, the reason I put DS.Employee.CreateNew() rather than new Employee() is just that this programming model could be achieved changing nothing more than naming and type nesting conventions for typed datasets, whereas getting to the preferrable (slightly - it's academical really, and makes no practical difference) new Employee() model would have required other changes, because DataRow has an internal constructor and can only be made by DataTable.NewRow(), obviously because the table contains the schema for the row.

Anyway, to me, the fact that the 'Employee' type is just a thin wrapper around a DataRow wouldn't really bother me in the least. I'd get a nice programming model that is way more OOP, but I'd also still have access to all the functionality that datasets already offer.

In fact, having written all of this I suddendly feel a bit tempted to make my own typed dataset generator!

modified on Wednesday, April 15, 2009 7:15 AM

GeneralRe: Database connection Pin
Pete O'Hanlon15-Apr-09 1:57
mvePete O'Hanlon15-Apr-09 1:57 
GeneralRe: Database connection Pin
dojohansen15-Apr-09 2:18
dojohansen15-Apr-09 2:18 
GeneralRe: Database connection Pin
Colin Angus Mackay15-Apr-09 2:33
Colin Angus Mackay15-Apr-09 2:33 
GeneralRe: Database connection Pin
dojohansen15-Apr-09 2:58
dojohansen15-Apr-09 2:58 
GeneralRe: Database connection Pin
Pete O'Hanlon15-Apr-09 4:27
mvePete O'Hanlon15-Apr-09 4:27 
GeneralRe: Database connection Pin
Colin Angus Mackay15-Apr-09 2:26
Colin Angus Mackay15-Apr-09 2:26 
GeneralRe: Database connection Pin
dojohansen15-Apr-09 3:27
dojohansen15-Apr-09 3:27 
GeneralRe: Database connection Pin
dojohansen15-Apr-09 3:30
dojohansen15-Apr-09 3:30 
GeneralRe: Database connection Pin
dojohansen15-Apr-09 3:36
dojohansen15-Apr-09 3:36 
GeneralRe: Database connection Pin
Pete O'Hanlon15-Apr-09 1:54
mvePete O'Hanlon15-Apr-09 1:54 
GeneralRe: Database connection Pin
dojohansen15-Apr-09 2:40
dojohansen15-Apr-09 2:40 
GeneralRe: Database connection Pin
Pete O'Hanlon15-Apr-09 4:38
mvePete O'Hanlon15-Apr-09 4:38 
AnswerRe: Database connection Pin
Colin Angus Mackay11-Apr-09 6:24
Colin Angus Mackay11-Apr-09 6:24 
AnswerRe: Database connection Pin
Fernando Soto11-Apr-09 8:09
Fernando Soto11-Apr-09 8:09 
AnswerRe: Database connection Pin
PIEBALDconsult13-Apr-09 4:16
mvePIEBALDconsult13-Apr-09 4:16 
AnswerRe: Database connection Pin
dojohansen14-Apr-09 22:02
dojohansen14-Apr-09 22:02 
GeneralRe: Database connection Pin
Colin Angus Mackay15-Apr-09 2:37
Colin Angus Mackay15-Apr-09 2:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.