Blog Home  Home Feed your aggregator (RSS 2.0)  
ObjectDataSource limitations, problems and possible solutions - Manuel Abadia's ASP.NET stuff
 
# Friday, March 10, 2006

In the past weeks I've been posting some detailed information about how the ObjectDataSource works in ASP.NET 2.0. Here's a summary of what was posted:

Part 1 - The basics

http://www.manuelabadia.com/blog/PermaLink,guid,c72852ae-1fdd-4934-a715-f565ceaf21cc.aspx

Part 2 -  Paging, Sorting, Parameters and Events

http://www.manuelabadia.com/blog/PermaLink,guid,f002752d-1258-475d-9ec0-eee3bd98d0a4.aspx

Part 3 - Optimistic Concurrency, parameter merging, caching and design time attributes

http://www.manuelabadia.com/blog/PermaLink,guid,eaa3eed8-f997-43c4-8c30-78c2f72d0c86.aspx

In those posts I pointed out some limitations or problems with the ObjectDataSource control. The only real solution here its to code your own data source control but it isn't an easy task. 

I'll summarize here the most important problems/limitations of the ObjectDataSource IMHO:

* Having to write a SelectCountMethod when your data source does support paging.

* All calls to the methods specified by the XXXMethod properties are made using reflection but the reflection data isn't cached so for medium/big applications this could be a bottleneck.

* It can't be extended without having to rewrite almost all of it.

* The control can't be used in some cultures because of the conversions from that it makes using the invariant culture instead of the current culture.

* The AffectedRows property is very important in order to get the GridView working properly so it's a pain to have to handle the inserted, updated and deleted events every time you use the ObjectDataSource.

* Filtering support is minimal and reserved only if you return a DataSet, DataTable or DataView.

* The cache doesn't support neither filtering nor paging.

* If you're using custom objects you can change the parameter dictionary for the insert, update or delete methods.

* There's no source code available to make little tweaks to the ObjectDataSource in order to adapt it to how you work instead of you adapting of how it works.

As I was very unhappy with the ObjectDataSource I coded my own data source control based on the ObjectDataSource but with a lot of improvements. As this wasn't a trivial job and required quite a few time, I decided to spend some more time on it to make it a commercial product. Take a look here for all the features of this new data source control:

http://www.manuelabadia.com/products/EODS_features.aspx

I have to remark that the control was designed to be very extensible so if you ever wanted something more than the ObjectDataSource you could save yourself typing and testing more than 10000 lines of code:

class diagram

 

I hope you find it useful. Feedback is welcome.

Update:
You can access to the other parts here:

ObjectDataSource in Depth (Part 1)
ObjectDataSource in Depth (Part 2)
ObjectDataSource in Depth (Part 3)

Tuesday, April 18, 2006 6:34:45 PM (Romance Daylight Time, UTC+02:00)
Hi
I am windows forms programmer just starting the fun with asp.net.
I think that tutorial is great, but I have just one question about creating new rows/entities.
The scenario shown here is perfect if you create "blank" objects. What if your business object is pre-initiated with some values?
Let's imagine you have some objects factory class which can initiate some of the values - like product name or generic description. Ok - forget about object factory - let us keep it simple - the class has some initialization logic in the constructor.
My Products constructor logic initiates the Name property to "Some great product". I'd like to show this value to user - displaying it in DetailsView and give him chance to make changes.
How to do that?
Wednesday, April 19, 2006 7:29:33 PM (Romance Daylight Time, UTC+02:00)
AFAIK there's no direct way to bind the DetailsView to a a default object when you're in insert mode to do what you want.

You can do what that handling the ItemCreated or ItemDataBound events. In the event, you should find each textbox and assign the associated default value.
Saturday, April 22, 2006 3:36:40 PM (Romance Daylight Time, UTC+02:00)
I've found another way to create and display pre-initialized objects. There are two steps:

Step 1. Business object has to contain information about origin - it has to know if it is newly created or loaded. I have added new property to base class: IsNew (bool).

Step 2. Fooling ASP.NET
All you have to do now is to make ASP.NET think that there's no need to create new object, just load one using CreateNew method instead of LoadById or similar. Another way is to use new parameter added to LoadById or set some discrete value to Id like (-1) or Guid.Empty.

But - if the object is loaded it will be stored using Update method not Insert. Here comes the IsNew property. Saving logic checks if the object has IsNew set to true and runs Insert instead of Update.

Advantages - This method supports layer separation, without any "magic" textbox initialization, so UI stays clear and simple. It may even simplify external interface of BLL, reducing Insert method.

Disadvantages - Keeping in mind to not use Insert method from user interface. Throwing exception may be good reminder.

Anyway - thank you for great tutorial, I'm going to link it in my blog.
Tuesday, April 25, 2006 12:51:39 PM (Romance Daylight Time, UTC+02:00)
Thanks for sharing your findings!
Wednesday, August 2, 2006 8:14:44 AM (Romance Daylight Time, UTC+02:00)
WoW~ I've just started to look into asp.net, this article is so good~
THX~
verydxz
Tuesday, July 1, 2008 11:44:51 PM (Romance Daylight Time, UTC+02:00)
I'd be curious to get your thoughts on this --> http://forums.asp.net/t/1280922.aspx
Andrew
All comments require the approval of the site owner before being displayed.
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

[Captcha]Enter the code shown (prevents robots):

Live Comment Preview
Copyright © 2020 Manuel Abadia. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.