Andy @ Work

Thursday, November 03, 2005

A partial solution to ObjectDataSource

It took a compromise, but I'm finally happy with my ObjectDataSource model.

After realising that I couldn't just bind the ObjectDataSource to my Business Object for updates and inserts I decided went down the path of creating two static methods on each BO. One for insert and one for update.

But it really grinded on me. ObjectDataSource wants the parameter names to be the same as the BO properties being bound to ~ hence if I bind to the User object's Username property, both my Insert and Update have to have 'Username' parameters. Except my companies parameter naming convention would have the parameter named 'p_username' (I won't go into the details for the p_. I like it and thats all there is to it.)

So to keep my naming convention I handled both the Updating and Inserting events and renamed the parameters in the InputParameters collection so that each parameter started with a p_ + lowercase letter.

But I started thinking about how many times I was going to have to write code like this. I'm lazy and I hate plumbing. But I'm also a bit of a perfectionist (a combination that makes someone look for the easiest right way to do something - which are often mutually exclusive).

I also didn't like my Business Objects design being dictated by the website. So in the end I created a series of ObjectDataSource helper classes. They have the horrible parameter naming convention, and the equally horrible lengthy parameter lists, and just wire up calls to the BusinessObjects. Oh and they're nicely tucked away in the web App_Code folder where hopefully noone besides control/page authors will ever think to use them.

I only wish that I had come up with this solution a couple of days ago.

0 Comments:

Post a Comment

<< Home