The Daily Dump

July 21, 2005

.NET

ObjectDataSource, Object Nirvana

I've just started an ASP.NET 2.0 project and I have to say I'm very impressed with the ObjectDataSource control so far. I point this nifty little control at one of my service objects (plain objects, not web services as yet), specify the methods for insert, select, update, delete, tell it the type of business object to expect (optional I think), hook a GridView control up to it, and voila, everything is working. No code! You don't even have to specify the parameters for the CUD methods -- it will figure them out itself. I just have the business object as my sole parameter, but apparently it can also do properties as parameters if you prefer that instead.

There will be code of course once the pages are fleshed out. The ODS can handle conflict detection (aka optimistic concurrency), but code is still required to check for this. I use NHibernate, which has its own "conflict detection", so I will be placing code in the same place to check for an exception instead of the number of objects updated.

That's later. For now I'm amazed at how little code I'm actually writing to get this application up and running. Tables, business objects, NHibernate files, service objects (using the flexible NHibernate query language), and web forms with ObjectDataSource controls, all with very little code in them. I'm not using cheap data access code in web forms to get the UI in front of the user, this is a simple, scalable, maintainable framework I can easily add to as the feedback and additional requirements roll in. The experience is more akin to Ruby on Rails than ASP.NET 1.1 development, and I'm loving it so far.

In 1.1 I used to have to retrieve my objects myself in the code, employ all kinds of tricks to either serialize the objects in the ViewState or Session, or track the UIDs -- then re-retrieve on postback, write over the properties with the DataGrid data, blah, blah, blah. A lot of code to maintain on every page. I am wondering what 2.0 does with the objects between postbacks though... There doesn't seem to be a re-retrieve, so I suspect the objects are being serialized into the ViewState. I should really look into this and see what is actually happening -- some objects can be quite large, and if I'm showing 20 objects or so in a GridView, that can be a lot of ViewState, especially if I'm only displaying some of their properties.

Posted by Adam Boddington at 01:04 PM | Comments (1)

Comments

May you post some example source code for this?

I´m thinking on using NHibernate and ObjectDataSource but I would like to know what has been your strategy.

Thanks in advance,
Juan.

Posted by: Juan at September 3, 2005 07:09 AM

Post a comment




Remember Me?

(you may use HTML tags for style)