The blog of Tobin

Tobins nerd blog on .NET, Software, Tech and Nice Shiny Gadgets.

Monday, February 21, 2005

Business Objects to DataSets and XML

If you use business objects in your .NET applications, you may find yourself in situations where you need to extract data from these into another representation. One example might be if you use some reporting software that expects to bind to datasets rather than business objects. I've been looking around for solutions to this problem, and here's what I've found so far. Please feel free to give any comments/success stories or alternatives if you know of them.

Option 1)
Rockford Lhotkas CLSA library has a class called ObjectAdapter. This flattens an object into a dataset. It doesn't follow relationships, and I think it's read only. But, it's a good start from the looks of things. I took the code out of his book, but if you google it I'm sure you can come find something downloadable.

Option 2)
There's a few folk talking about something called UI Mapping (a term coined by Paul Wilson who makes WilsonORMapper and soon the WilsonUIMapper). This is basically taking objects and mapping them to UI widgets. Whilst a UI mapper won't necessarily help you get objects into datasets, it has caused people to think about this kind of problem. One project that I think looks promising is NView (http://blogs.wdevs.com/phirephly/). This is not a UI Mapper as such, but a tool to allow you to map from one conceptual view to another. You can easily map from an object graph to a dataset, for example. Also, the view can be bi-directional, which means that 2-way databinding is possible. I tweaked the example source code and was generating heirarchial datasets from objects in 7 lines of code.


Option 3)
What I've been doing in the past is using some home grown code to convert an object graph into XML. I then use this to create reports using XSLT. It might not be great for all needs, but so far it's been handy for web based invoices, purchase orders, letters and that kind of thing. The code works using reflection to walk an object graph and write out XML. It also allows you to specify a fetch plan so that it doesn't export the entire object graph. I can't share this code, but it wasn't too hard to write based on the power of reflection. You may wonder why I didn't use just make my objects XML Serializable - personally I find this tricky in many cases because you have to do a bit of tayloring to make your classes suitable.

I've not tried the above approaches in a commerical project yet, although I especially like the look of #2. A while back I was talking to Thomas Tomiczek who works on Thonas EntityBroker product. If I remember correctly their product also uses a kind of ObjectAdapter/ObjectView to allow mapping of objects to grids/GUI. Has anyone used this, any opionions to report back?


0 Comments:

Post a Comment

<< Home