I'm not sure how feature complete projections are in Hibernate 3.1 but it exists.
I have had a huge need for projections for quite some time now as I often need to project a flattened view of queries. A particular case is when I adapt the result set into a different model - a dBase table for example. I do this for a GIS framework I'm developing which uses ESRI shape files and dBase files to store spatial data. So a typical process for me is to QBE in NHibernate, then adapt that result set into a GIS layer (ShapeFile + dBase table). For now however, it's been very tough as I have to traverse the List and reflectively pluck out the properties (and nested types) to stuff it into a dBase table. I need to be able to do this genericly as I'm building my own framework that will work will multiple data models at once. So I can't do things like foreach(Entity e in results) { /*...*/} - it must ne agnostic to the result set.
Serg, as if you don't already have enough on your plate, but I wondered if you could throw a bone on a neat way to do this? Making use of an adapter pattern, I wanna be able to form a projection as efficiently as possible. Of course, once projections is ported over to NHibernate, this would greatly simplify things.
As it stands now, I'm actually doing a bit of a hack to get it to work, using DLinq's projection capability. So my sequence is: [1] load and build the configuration, [2] retrieve the session, [3] QBE, [4] project the result set using DLinq taking advantage of C# 3.0 anonymous types, [4] adapt into dBase file. There is nasty overhead with this because I have to first convert the IList into a List<T>, thereby forcing a complete fetch (needed anyway to build the dBase file), finally to adapt it.
Serg or anyone, how would you go about this?
Thanks in advance,
Timex
|