Is this NHibernate sample still valid? - nhibernate

Or the concepts/best practices used there are now deprecated? I'm just starting to use NHibernate and I'm having a hard time finding good real life samples.
http://www.codeproject.com/KB/architecture/NHibernateBestPractices.aspx

As you can see for the dates the author (Billy McCafferty) didn't update it in a long time. There is so much more on the NHibernate ground now but most of the concepts in that article still apply.
You may want to checkout additional sources like:
http://nhforge.org/
http://fabiomaulo.blogspot.com/
http://fluentnhibernate.org/
If you are using NHibernate in web applications, Billy McCafferty built an excelent framework on top of NHibernate and ASP.net MVC. http://www.sharparchitecture.net/
And this open source app is an awesome sample: http://whocanhelpme.codeplex.com/

Related

PLINQO for NHibernate. Mappings and Entities.

I recently posted a question regarding NHibernate. This lead me to check Codesmith's framework PLINQO for NHibernate.
At the same time, i was reading a tutorial on nhibernate at their official site (as i was looking at the generated project by PLINQO).
I am not an expert on NHibernate but what i am looking at right now (PLINQO Generated NHibernate project) looks to me very sloppy, pretty much a recipe for disaster. It creates a set of "Entities" that i am guessing is the business object? A big mess to my eyes.
Does anyone has experience with Codesmith's NHibernate?
Can anyone point me to a mc daddy of NHibernate. I have found so many variants so far that i am already overwhelmed with all this.
Thanks you.
I work for CodeSmith Tools. How do you feel the generated project looks sloppy? How would you improve it? We try to separate out the entities (POCOs) / hbm's for consistency and easy of use (as Randy detailed above). The Entities are generated directly from what is defined in the hbm file, which can be customized without losing your changes.
The generated project follows the architecture of Linq-to-SQL and Entity Framework. We feel this allows developers on the Microsoft Stack to switch between backends quickly (NHibernate to EF or EF to NHibernatE) while minimizing the amount of code changes.
The generated datacontext manages the NHibernate sessions for you while giving you access to query extensions, caching and much more. Also, you don't lose any core NHibernate features as we just extend the core libraries. All of the core features are available on the DataContext under an advanced property.
P.S., The best place to post questions and get a timely response is via our forums.

nHibernate + Mvc3 Sample Application

I'm looking for a decent codebase that demonstrates how to use nHibernate as the persistance layer in an asp.net mvc3 project.
The two key pieces of understanding that I am looking to develop are
How to deal with ISession and
ISessionFactory.
How to implement the repository pattern without leaking any details of its nHibernate implemenation.
I'm aware of Sharp Architecture and reading through that now - Its interesting but I'm more keen on finding a straight-forward web app to pick apart than another framework to learn.
Thanks in advance.
I put together a project that offers an example of how to do this using nhibernate and asp.net mvc 2. The repository and nhibernate implementations will be almost the same. Probably the biggest change will be the ioc / dependency injection piece. Take a look. It should provide a solid starting point. Here is the URL.
http://gpsnerd.codeplex.com
Let me know if you have questions.
Bob
Take a look at https://bitbucket.org/FunnelWeb/dev
FunnelWeb is a blog engine based on ASP.NET MVC and NHibernate.
It is opensource and used by many bloggers/develoeprs

Entity Framework vs. nHibernate for Performance, Learning Curve overall features

I know this has been asked several times and I have read all the posts as well but they all are very old. And considering there have been advancements in versions and releases, I am hoping there might be fresh views.
We are building a new application on ASP.NET MVC and need to finalize on an ORM tool. We have never used ORM before and have pretty much boiled down to two - nHibernate & Entity Framework.
I really need some advice from someone who has used both these tools and can recommend based on experience. There are three points that I am focusing on to finalize -
Performance
Learning Curve
Overall Capability
Your advice will be highly appreciated.
Best Regards,
I would use Nhibernate. I would pickup Sharp Architecture as a great framework that wraps NHibernate, ASP.NET MVC and a bunch of other open-source tools into a coherent whole that will give you a solid architectural foundation.
Nhibernate is more mature than EF4. It is well supported by the community. As long as you are willing to get your hands dirty from time to time, you will like it. It's support for LINQ is currently a little weak but it is rapidly getting better. The learning curve is not bad, but things like session management can be a little confusing at first. One of the reasons I like Sharp Architecture is they have all the NHibernate stuff you will need in place and plenty of guidance on how to use it properly in an ASP.NET MVC project.
EF4 has the MS stamp of approval. It is pretty good now but still behind NHibernate. It is a perfectly good choice and you will find lots of docs from MS, MS support and eventually more developers that are familiar with the ins and outs. I should also mention that the Sharp Architecture folks are adding support for EF4 to their overall framework. They will still support NHibernate, but you will be able to use EF4 if you like.
I think it takes more time to learn NHibernate.
EF provides graphical designer, unfortunately NHibernate doesn't have a generic designer. BTW it's not a problem. If you design in domain-driven (DDD) manner, you will design your entities first and you don't care about database structure (as you used to), NHibernate will handle that for you.
EF 4 got closer to NHibernate. I wouldn't start working with EF 3.5, it lacks a lot of features.
If you think NHibernate is too complicated at first sight, you can start with frameworks built on top of NHibernate. ActiveRecords and Sharp Architect are good examples.
AFAIR EF 3.5 supported only SQL Server 2000. It couldn't handle the new data types from SQL Server 2005. I have no information on EF 4 but I suppose it support these improvements.
If you use NHibernate in real word applications, you have to build an infrastructure. E.g. I implemented the Unit of Work and Repository patterns to be able to write tests and create layers in my application. You have to expect the same using EF. Detaching and attaching entities in EF 3.5 was not an easy thing, I had to write tricky extension methods to mark fields dirty and so on. I hope they solved it in EF 4. There is no such problem with NHibernate.
You don't have to write HQL queries in NHibernate, you can use the LINQ provider. I think it's very important. :)
All in all NHibernate is a mature product with good community and commercial support. EF is young but strongly supported by Microsoft. Oh, and EF is a Microsoft-only thing while you can port your NHibernate knowledge to Java as well. It this counts for you.
I'm trying to look into this...
After building apps into both, NHibernate is definitely more powerful, but it's also quite clunky where EF is very clean. And after working with Rails/ActiveRecord, both are very feature rich in comparison, so either would definitely work!
I noticed that NHibernate keeps track of what it just ran, and if it just ran a statement, it doesn't exectute it again, so a properly designed app will run minimal database statements. I know that EF is not exactly slow either, but I'm not sure if it caches statements and results in the same way. For a large app, this could save some database resources!
So in short, NHibernate for functionality and configurability, and EF 4.0 for cleanliness and a quick easy learning curve. Also, one should expect EF in the next version or two should may catch up to or surpass NHibernate in functionality too, so it may make sense to have some familiarity with both.
just take a look at this
http://gregdoesit.com/2009/08/nhibernate-vs-entity-framework-a-performance-test/

Can you point me to current examples using NHibernate in an ASP.NET MVC2 app?

Can anyone point me to any self-contained, complete, current reference materials/projects using NHibernate in an ASP.NET MVC2 application?
I have looked at Sharp Architecture, but I am not sure I need the complexity in that project. I certainly don't know enough about it to know if it is over-engineered for my purposes.
I would like to see more types of implementations to gauge the various ways people have skinned this cat.
This video series on nHibernate is great and they are using MVC Storefront as the base for the work:
http://www.tekpub.com/production/nhibernate
Code is here:
http://github.com/robconery/Kona
Another great MVC Resource (if you need one) is their MVC Videos:
http://www.tekpub.com/production/aspmvc
and
http://www.tekpub.com/production/byob
I can't recommend them enough.
Max Schilling
Gave it to Max for just answering. :)
But, for the record, here's additional apps to consider, should you end up here:
Sharp Architecture (the Northwind app
is okay but lean, not typical
enterprisey stuff)
Who Can Help Me? (great stuff and
kept up-to-date)
FubuMVC has good sample apps (based
on MVC not MVC2 at the time of this
post)
Thanks.

How to map the NHibernate Data Model to the Domain Model?

I started creating a domain model and now I asking myself, how can I map this domain model to a NHibernate Data Model ((using Fluent NHibernate)? Is there anywhere a good and simple example of how to do that?
With Data Model I didn't think about the physical/relational Database Model(!) What I meant was the Data Model in the Data Access Layer. So maybe I should change the term into Data Access Layer Data Model?! I hope some of you can follow me^^
I'd start reading the NHibernate manual, it's not very long and in chapter 5 covers many details about the different options that exist in the mappings. I find also important chapter 6 about collection mapping an 8 about inheritance.
Maybe you can start with the getting started page from fluent nhibernate, but to understand all the options you will have to lookup their meaning in the NH manual as Fluent NHibernate assumes that you are already familiar with the XML.
I don't have enough information about NHibernate in Action but the good old Hibernate in Action was also useful because the mapping examples for the Java version are in most cases valid on .NET and provides examples and detailed information on each parameter.
This is the easiest one for getting started in a step-by-step manner that I have come across
Your very first NHibernate application – Part 1
However, I would recommend that you simply download the latest binaries from the Fluent NHibernate download area rather than getting the source from Subversion, installing Ruby and building it locally on your machine but that's up to you.
Well, have you tried www.nhforge.org and http://fluentnhibernate.org/ ? Both have excellent introductory guides.
Take a look at the Getting started page on the Fluent NHibernate site. And definitely take a look at the Auto Mappings capabilities. I was up and running in a couple of hours. Good luck!