Wednesday, March 21, 2012

Complex data operations

The two-way databinding using the ObjectDataSource is all very nice if you are using simple one-dimensional DTOs, and there are now a reasonable number of code samples about showing you how to do that. However, most people in the real world end up with some fairly complex objects that they want to use (e.g. another class as a property, or a collection as a property, rather than just plain types). Has anyone found any good examples on how to do this? Can it be done declaratively at all, or do you really have to go into code? Brian Johnson's postASP.NET 2 Data Binding Hell - Part II - The Snickering of the ObjectDataSource pretty much explains the problem better than I can, but unfortunately he doesn't go into details on how to work aroudn the problem. I've done all sorts of playing around with the event model, catching the FormView's Updating event so that I can, for example, load the content of radio buttons in to my objects (which are definitely not DTOs), and then catching the ObjectDataSource's Updating event so that I can then applymy model's way of loading/saving data, rather than the one that MS AJAX assumes you are using, but it still really doesn't feel much like best practice.

Personally, I have deplored the adoption of DataSources for databound objects. Yes, its slick for the UI type programmer but if you want performance and flexibility... my approach is to handle it with code. You can absolute control and handling of how well you want everything to perform...I'll use the gridview for display when I really do not need to code to a repeater model (which is much more conformat but also albiet more difficult to program to in some cases).. then I will use a invocation of say a edit event - one thin I like in the whole MSFT Ajax line is the ModalPopUP - and I'll load the form there (not using the formview - its glitz in my opinion)... But I exclusively codebehind because I belive in the true n tier approach and UI is UI, Business Modeling is Business Layer and Data Access is the DAB... I like the seperation becuase in the end it is actually the most performant code you can write - but not the easiest...So if you are dead reckoned on the formview consider:

Nested Update Panels that load corresponding FormView

No comments:

Post a Comment