CSLA with NHibernate and ADO

CSLA with NHibernate and ADO

Old forum URL: forums.lhotka.net/forums/t/2741.aspx


burmajam posted on Friday, April 20, 2007

Hi all,

I'm using CSLA with ADO for persistance, and I want to try using NHibernate also, as few of you said it can be used successfully. As I have few situations where ORM can't do the job and manual work with ADO can, I'm interested if someone mixed those two approaches with CSLA and how.

Tnx

rbell replied on Monday, April 23, 2007

I have not experienced any issues mixing CSLA classes populated by NHibernate with CSLA classes populated by ADO.NET.  Like you, there were a few cases where ADO.NET was a better choice than NHIbernate.

One thing I did was create a simple utility class that returned an ADO.NET connection object using the connection string from the NHibernate configuration.

One downside of mixing the two is maintenance on the classes later on.  So I would suggest sticking to one data access architecture as much as possible and make sure to document the exceptions.

I am not sure what your situation is that is causing you to need to use ADO.NET vs NHibernate, but I would also urge you consider to consider all other options before mixing architectures....such as mapping entities to stored proceedures (NHibernate 1.2 supports this).

rdrunner replied on Monday, April 23, 2007

burmajam:

Hi all,

I'm using CSLA with ADO for persistance, and I want to try using NHibernate also, as few of you said it can be used successfully. As I have few situations where ORM can't do the job and manual work with ADO can, I'm interested if someone mixed those two approaches with CSLA and how.

Tnx

 

Hello...

You can mix and match the way you like it. To take a closer look at a possible way of moving the DA-Code out of your Business Object, you should watch the DNRTV Episode 60. There Rocky explains the various ways of getting the Data into your BO... (The DeepData Project is covered there)

The DTO Aproach seems best for this mixed Scenario. This will allow you to remove the full DA code from your BO and remain totally transperant. So you can fill your DTO from "any" Datasource and then contruct your BO from those DTO. You basically dont care where the DTO comes from, and you can easily map the fields to the BO once you got it. He also covers how to configure the "Provider" which will return your DTOs with your configuration.

Take a look... It was a good show ;)

 

burmajam replied on Monday, April 23, 2007

Hi guys,

Tnx for your answers. I saw that dnrTV show. It was really usefull, but I didn't thought of using DTO as you mentioned for mixing those two. It looks like good idea. I'll watch it again and think about it.

Problem that I've found with NHibernate is mapping one business class to few tables on fetching, while insert and update should write to only one of those tables. It is association table. I don't know how to do it with stored procedures, but honestly I didn't try. I'm just researching posibilities of NHibernate and trying to figure out how could I do some "tricky" things like this with it, becouse ADO.NET does it without problems but NHibernate surelly does have some few really usefull things like CachingLevel 1 and 2, DB independence, distributed transaction support and so on.

DavidDilworth replied on Thursday, May 03, 2007

I can (at last) announce that there is now a ProjectTracker.NHibernate example solution on the CSLAcontrib site on CodePlex.

Can I suggest that all future CSLA / NHibernate questions (especially those related to the ProjectTracker.NHibernate solution) are posted on the CslaContrib forum.

Thank you all for your patience and support.

Copyright (c) Marimer LLC