views:

319

answers:

6

i'm building a 3 tier wpf application. i heard that nhibernate is best for web applications.

i know how to use nhibernate.

should i use it or not??

are there any recommended or mappers that will be more suitable?

+2  A: 

NHibernate with Fluent NHibernate seems like a very nice ORM combination, with Fluent really getting rid of the tedious XML config stuff.

I will not venture into saying that it is the best solution or not, but several other ORMs require you to maintain external configuration files which really breaks useful things like refactoring.

That said, whether it is suitable for use in WPF applications vs web applications: usually, web applications have a more constrained process model than Windows clients. So if NHibernate is suitable for web apps, imo it should be more than suitable for Windows clients. They are statefull and have access to more memory and cpu power.

Even more, if you are building a 3-tier application, that is data access and business logic runs on a server, perhaps you access these tiers via web services which is only another form of web application.

Perhaps if you could elaborate on what you "heard" about NHibernate being only suitable for web apps we could understand more.

Peter Lillevold
A: 

You can certainly use it, but you need to be very careful about how you manage your sessions (do not keep one session open for the duration of your application) and, in particular, how you use lazy initialization (make sure you look into detached objects, otherwise you're likely to find yourself faced with a LazyInitializationException and no obvious way to fix it).

Volte
yes yes of course i faced those exceptions in past
Chen Kinnrot
+3  A: 

It would be fair to say that you can get into trouble with NHibernate if you don't spend the time to understand how it works. That said, the learning curve starts very shallow but ramps up fairly significantly for some of the advanced features.

I would recommend taking a look at:

  • NHibernate In Action : Great book for learning NHibernate. Doesn't cover the latest version, but hey "that's what the internet is for".
  • NHibernate Query Analyzer : Tool for editing HBM mapping files and for looking at the results of HQL queries.
  • NHibernate Profiler : NHibernate debugging tool. Detects common mapping problem scenarios for you (eg. N+1 select problems) and gives you advice on how to solve them.

Of course, if you are only doing basic ORM operations then take a look at ActiveRecord. It's built on top of NHiberate, but does away with any mapping requirements - you just decorate your objects with attributes.

Codebrain
fluent nhibernate auto mapping does the same...i have some nhibernate experience, i just wanna know why its recomended only for web appz
Chen Kinnrot
It sounds like you know what you're talking about. If you're able, can you please elaborate on your statement - *"..You can get into trouble with NHibernate if you don't spend the time to understand how it works."*
Jim G.
+1  A: 

NHibernate isn't tied to any particular environment. You can just as easily use it in a WinForms/WPF application as you can a web app. Just be conscious of your session management, but that's something you should do regardless of environment.

James Gregory
A: 

If you ask the question this way the answer is DO NOT USE IT (as any other ORM). NHibernate is few steps behind the origin and even this is not an issue. The main issue is that ORMs cannot solve impedance mismatch problem in principle. It may make your life easier but it depends on your project (i wouldn't think this is the case).

I'd better concentrate on classic client/server scheme for better understanding how the things work. You need to know (at least) limitations of C/S architecture before you start using any ORM.

UserControl
I agree with you in principal but I'm not sure if impedance mismatch really presents itself often enough to be of actual concern.
A: 

Start designing your application without knowing the solution you'll use for data persistence. It will be rock solid.

Nelson