Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

.NET

LINQ to Web 2.0


Are Typed DataSets a Viable Data Tier?

Typed DataSets in ADO.NET 2.0 are easier to work with and much simpler to use than Typed DataSets in ADO.NET 1.0/1.1. The basic premise behind a Typed DataSet is that an XSD (XML Schema Definition) file is created that models a database schema or a subsection of the database schema. This XSD is then converted into a C# class at build time, is usable at runtime, and provides IntelliSense-aware members. In addition, we thought we might be gaining a big benefit with strongly typed members. Unfortunately, the strongly typed members are really just a facade. Under the hood, the Typed DataSet is still just a DataSet that stores everything in terms of objects. The amount of unnecessary typecasting that goes on with Typed DataSets was unacceptable.

To get data into a DataSet, you normally use a DataAdapter. In the case of a Typed DataSet, there are specialized TableAdapters that are responsible for querying the database, filling tables, and persisting changes back to the database such as inserts, updates, and deletes. In Listing Two, which populates a Typed DataSet, there is no inline clue, cue, or faint reference to what data is being populated other than the method name. Because I wrote the code, I know that GetAllBookmarksWrtUser on the BookmarksTableAdapter class actually refers to a stored procedure in my database called moniker_GetAllBookmarksWrtUser. Thankfully, I had some naming conventions that made things easy to decipher. But what if I was looking at this code and wasn't the author? Or what if I didn't have direct access to the database? I would have to spend considerable time digging through the contents of the Typed DataSet to figure out everything that is going on. I would much prefer to be able to see the query from the same perspective as the code that binds the query results to the GUI. My usual habit of right-clicking a confusing method (such as GetPopularTags) and choosing "Go to Definition" doesn't help me here. Why? Because all it does is take me to the definition in the Typed DataSet, which just creates more spaghetti code, creates a generic data adapter, and fills based on parameters. There's no useful information. I have to crack open the XSD for the Typed DataSet to find out what's really going on.

     
BookmarksDataSetTableAdapters.BookmarksTableAdapter bookTA = 
    new BookmarksDataSetTableAdapters.BookmarksTableAdapter(); 
BookmarkList1.DataSource = 
    bookTA.GetAllBookmarksWrtUser( User.Identity.Name, pageIndex, 
       numRows, ref totalBookmarks); 
TagDataSetTableAdapters.TagsTableAdapter tagTA = 
    new TagDataSetTableAdapters.TagsTableAdapter(); 
TagList1.DataSource = 
    tagTA.GetPopularTags(DateTime.Now.AddDays(-30), User.Identity.Name); 
recentTagsList.DataSource = 
    tagTA.GetRecentTags( DateTime.Now.AddDays(-30), User.Identity.Name); 
Listing Two

The code to update using Typed DataSets is straightforward. Make the changes to the object. The TableAdapter can then convert those changes into a SQL execution (inline SQL or stored procedure) and send that to the server. Typed DataSets are extremely powerful, but in any data tier I plan on using with any regularity within the enterprise, I want true and legitimate members on classes (not just typecasting wrappers!). I want model layer abstraction. I want real data types instead of typecasting, and most importantly, I dislike the fact that the information being retrieved is extremely difficult to find. You need to dig deep into the XML of the DataSet (which you can't even see in VS 2005 without explicitly requesting the XML editor) to see the queries that are being executed against the server. Even after you find the queries, they are in a syntax that is painfully difficult to read. This entire infrastructure makes difficult the task of reviewing code, analyzing queries, and even inferring what data is flowing and where it's flowing to.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.