NHibernate

NHibernate

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


JHurrell posted on Tuesday, November 07, 2006

I've just started a job with a new company and we're in the process of investigating different code generation and data access tools. So far, the group has looked at AndroMDA with NHibernate and ActiveRecord with NHibernate.

AndroMDA is pretty intense. It generates your classes from UML (version 1.4) diagrams and we all know that UML isn't exactly complete when it comes to describing .NET objects.

ActiveRecord is based on the Ruby on Rails efforts and is also compelling. I don't really care for it that much because there seems to be tight coupling between the objects and the database.

I was hired partly because I have some CSLA experience, and now I'm trying to sell it to the group. The application we're developing could benefit greatly from the deliverables that CSLA provides, but the group really loves the idea of using NHibernate.

I think I could really seal the deal if I could explain how NHibernate and CSLA work together. I've searched the forums and I've read the threads that talk about the two, but I didn't really see any discussions of workflow.

Would some of you CSLA/NHibernate users please provide a brief description of how you approach creating your classes and database objects.

- John




ajj3085 replied on Tuesday, November 07, 2006

I think your best bet is to convience them that Csla and the other frameworks are solving two different problems.

NHibernate et. al. are trying to abstract away your writing of Sql, so that you talk to the database through objects.

Csla on the other hand is trying to help you build objects which satisify use cases.  Your objects here probabaly won't look like your tables at all (or very much).  You may have many more objects than tables, in fact that's very likely.

The two complement each other well though.  Basically, you UI would see only your Csla based assembly.  Your clsa based assembly in turn would see your NHiberate objects.  You'd use them only in the DataPortal_XXX methods when you actually need to talk to the database.

That's probably why you don't see much discussion beyond this, because it should be fairly simple.  Instead of using Ado.Net in the DP_XXX methods as Rocky does, you use the NHibernate objects you create.

HTH
Andy

JHurrell replied on Tuesday, November 07, 2006

Andy,

Thanks for your response. I already have a good handle on what CSLA and NHibernate do and how they differ.

What I'm really looking for is a walkthrough of how you actually use them together. Do you use custom CSLA/NHibernate CodeSmith templates to generate your CSLA objects from an existing database model or do you manually create your CSLA objects and then decorate the private member variables with NHibernate attributes?

I want to make sure I have answers to some of their questions. One of the things I love about CSLA is that I can use CodeSmith to generate sophisticated CSLA objects from a database table or stored procedure. Even though CodeSmith wants to go against a table or proc, I can create a temporary table that contains columns from many joined tables. In this way, I've created an object that may span many tables.

I'm having trouble seeing how I do this if were to use CSLA with NHibernate. It seems that one of the favored features of NHibernate is that it can create the database from the objects and not the other way around.

- John


ajj3085 replied on Tuesday, November 07, 2006

John,

Sorry, I don't have experience using NHibernate, which is why I just rehashed what others have said.

Now, as to your points on NHibernate...

I wouldn't base Csla objects on tables, although I guess that's how people using CS are doing it.  Ideally you'd create the Csla object from UML or something like that.  Then you can use NHibernate to build the backend objects and DB (which is a neat feature of Nhibernate that I didn't know about).

The main advantage is that you should be able to develop both your data layer and business layer at the same time.

At least that's how I'd proceed.  I have found that by first building out at least the stubs and general design of the business layer, I make sure I'm not being influenced by the database design, because it doesn't yet exist.  I think this has led me to better business object design.  Then I worry about how to store the data from the business objects.

Andy

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