Way to get fields from multiple tables using Enterprise Library 5.0 Accesors

Topics: Data Access Application Block
Aug 12, 2012 at 8:20 AM
Edited Aug 12, 2012 at 8:23 AM

Hello guys!.

I am using EntLib 5 for a project and I am stuck trying to figure out a way to get different fields from joined tables and my object list results using accesors.

For example I have a "Contact" Class with a "Country" linked Class Property in it. The idea is to query with a join on both tables and get all the country info along with the Contact info for the request ContactId.

Is there a practical way to do this using the Accesors abbreviated way? or should I just go doing the fields vs property manually mapping using the filled DataReader after executing the query?. I have googled but I haven't found anything.

Thanks for the help and the time for this question.


Aug 13, 2012 at 7:22 AM
Edited Aug 13, 2012 at 7:29 AM

I think you should look at Creating Result Set Mappers.  Once you create the IResultSetMapper you can use it instead of the typical row mapper.  See this posting for an example: http://entlib.codeplex.com/discussions/229910.

As an aside (since it's not something you would just do on a whim), this could be a case where using CQRS to have a read model that flattens out the hierarchies could be useful.  See the pattern & practices CQRS Journey if you are interested. 

Randy Levy
Enterprise Library support engineer

Aug 14, 2012 at 4:07 PM

Thanks Randy. I will give it a look.

I am starting in the "ORM" world, and besides using the useful blocks on the Library I think I could make it work as one occasionally. Do you find these approaches good enough to use the library as an ORM like tool or should I just better go with another option?.

Aug 15, 2012 at 3:26 AM

I would describe the Data Access Application Block as a wrapper over ADO.NET.  With the release of Enterprise Library 5 and the addition of accessors and mappers the functionality of the block was increased as well as making it more ORM-like but the fact is that the DAAB is not an ORM.  Although useful, accessors are read-only so they really only help with querying data.  

You could put in time and effort to make it more ORM-like but if that is your goal then perhaps it would be better to just start out with a pre-built ORM?

Randy Levy
Enterprise Library support engineer