The ASP.NET 2.0 ObjectDataSource Revisited - or - Give Me That Extra Inch!#

Since I cried tears of joy over the new ObjectDataSource in ASP.NET 2.0, two things have happened:

The first one is only important if you're doing, well, anything at all in .NET really. By that I mean: go get it already dammit! It can now load, visualize, search and decompile assemblies from any .NET runtime, including the Whidbey ones, so this killer tool just became even better! I just used it to check upon my remark to see if the ObjectDataSource would cache the runtime type information it found - but it doesn't look like it does. This would imply a significant overhead on assembly probing and reflection each time the data is fetched (if it isn't read from the cache of course). Anyway, let's call that "room for improvement" or "never mind you twat they know bloody well what they're doing so stop decompiling and jumping to conclusions already".

Regarding the second one, I thought about naming this post "ASP.NET 2.0 DataBinding - Close But No Cigar" or even "Microsoft still doesn't get DataBinding" - but that's just a little harsh and arrogant ;-) It would probably generate more attention though, but for now, I'd just like to subtitle it "Give Me That Extra Inch".

So what's the problem? Let me just briefly sketch the right context here... Most modern applications are n-tier, which means your data is stored in a data tier (which is backed by a relational database most of the time), it passes a business tier holding all your core business logic, and then reaches your user interface tier. The data itself is "disconnected", meaning no connection (to a database or other data store) is kept alive and the data has no memory of where it came from. In .NET land, this is represented by the DataSet object with embedded DataTables, primary keys, relations, constraints, ... - thus providing an in-memory representation of a relational database. But I'm sorry for boring you; you know all of this, right?

So the two main points in modern data-driven enterprise development are: n-tier and datasets.

And although we (and certainly Microsoft) have known all this for years, there's never been any real support for this in the .NET framework or in the samples: 95% of all examples still go straight from the UI to the database. And that's frustrating for you as an enterprise developer, since they're not realistic or useable in your world.

Now I thought for a minute that the ObjectDataSource would finally be able to solve this issue - as I've said before, it's a DataSource control that fetches data from any object through declarative configuration. So just hook it up to a remote business component or web service that returns a dataset and you've succesfully decoupled your UI from your other tiers, while maintaining your easy-to-use declarative ASP.NET databinding.

Well, yes, but only partially. While this works great for a lot of scenarios, it fails when things get just a little bit more complex: it won't work when you have multiple data tables in your dataset, which is a very common practice when you're fetching related data. Since you're working with multiple tiers, you'll want to reduce the number of calls and get chunky in stead of chatty conversations. So you try to group as much related data in a dataset as possible. And then the client can look at this data as individual tables but also navigate the relationships between them.

And a data source having multiple tables has always been supported in databinding as well, using the data member to indicate which table in your dataset should be used. The new databinding classes also support this through "views" on the data, which you can retrieve by the view name. Unfortunately, here's the drawback: the ObjectDataSource only supports one table from the dataset. It actively checks on the retrieved object to see if it's a dataset and if it is, it just uses the first table to create its one and only view. (How do I know? Reflector for president!) Even the documentation says so: "The ObjectDataSource control supports only one data source view". So that's where it ends I guess. They really did come close this time, but I'm still a little disappointed.

I need to get a little more chunky than chatty too, so just to summarize: please make the ObjectDataSource support multiple views if there are multiple DataTables. Thanks. That's all I wanted to say really :-)

Thursday, June 08, 2006 6:11:22 AM (Romance Standard Time, UTC+01:00)
Very interesting comments and do realize this is 2 years later, but I still am thinking this is a problem that does not have an answer or easy answer.

Here is a link to where I have been working a similar problem from:
http://forums.asp.net/1308562/ShowThread.aspx#1308562

okay sorry for the long delay ................I still can not find anything for my answer.

But I did find an article which really describes the beginning of my problem.
http://msdn2.microsoft.com/en-us/library/4xz507ds.aspx

This code creates 1 dataset which contains 3 datatables with the appropriate relationships.
=====================================================
Although, this code falls short of my expectations. I was hoping for this to expand into .RowFilter.
I was also hoping the datagrid would have been bound to all 3 tables at the same time. So that I could have displayed 1 field from the orders table, 3 fields from the orderdetails table and then 1 field from the customers table. Much like relational select query using sql.

I thought the DateViewManager would support this with .rowfilter but it does not appear so

locDataViewManager.DataViewSettings("Customers").RowFilter = "id = 200"
locDataViewManager.DataViewSettings("Order").RowFilter = "id = 20332"
locDataViewManager.DataViewSettings("OrderDetails").RowFilter = "id = 98773"

I then could cache this Dataset..and requery the DataSet every time I wanted a different filter of the
same data with out ever having to normalize the data into one table or querying the sql server.

I thought the dataset was to be a remote database object much like a tiny (in-memory) database which could be cached and then queried at will. Just as if I was working with a real sql relational database which had 3 tables.

But nothing on the internet says this is possible. So my point is what use are the

custDS.Relations.Add("CustomerOrders", _ custDS.Tables("Customers").Columns("CustomerID"), _ custDS.Tables("Orders").Columns("CustomerID")) custDS.Relations.Add("OrderDetails", _ custDS.Tables("Orders").Columns("OrderID"), _ custDS.Tables("OrderDetails").Columns("OrderID"))

if only one DataTable can every be respresented or queried?


hmmm...very disturbing.

Could you provide any insight?
Comments are closed.
All content © 2008, Jelle Druyts
On this page

Recent Photos
www.flickr.com
This is a Flickr badge showing public photos from Jelle Druyts. Make your own badge here.
Advertising
Top Picks
Statistics
Total Posts: 344
This Year: 7
This Month: 0
This Week: 0
Comments: 522
Archives
Sitemap
Disclaimer
This is my personal website, not my boss', not my mother's, and certainly not the pope's. My personal opinions may be irrelevant, inaccurate, boring or even plain wrong, I'm sorry if that makes you feel uncomfortable. But then again, you don't have to read them, I just hope you'll find something interesting here now and then. I'll certainly do my best. But if you don't like it, go read the pope's blog. I'm sure it's fascinating.

Powered by:
newtelligence dasBlog 2.0.7226.0

Sign In