Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate removes DAL?

Am I right that using NHibernate (or any other ORM) removes the necessity of DAL? Or not?

like image 380
Niccolo Avatar asked Dec 08 '22 06:12

Niccolo


2 Answers

I was trying to think of how to answer this question but the answer is NO, it doesn't remove the neccesity of a DAL rather than becomes part of that DAL, what you were doing before no doubt was having access objects which called either sql code build in code or was calling stored procs.

It was then constructing say a Bill business object with data perhaps from multiple tables and then returning that. It was a lot of hard work and usually involved maintainance by itself.

NHibernate takes the heavy lifting work out of this task (and does other things) but you still may want "Manager" classes as part of the data access layer to do manipulation before objects are returned etc.

So allthough I'm doing a terrible job of explaining it, NHibernate doesn't remove the need for a DAL it just changes what your DAL is made up of.

like image 169
krystan honour Avatar answered Jan 02 '23 08:01

krystan honour


You need a DAL, the question is what do you do in the DAL. In a .NET project with NHibernate, I use this organisation

  • MyProject.Core.DomainModel : in this project only the .cs and mapping files (.hbm.xml)
  • MyProject.Repo : in this classes you use NHibernate method like Get, Load, make query ....
  • MyProject.Service : from these classes, I call the MyProject.Repo methods
  • MuProject.UI : ASP.NET, ASP.NET MVC, Winforms .....
  • MyProject.Service.Tests : all the unit test to test the service

I give you an example, I'd like get all active Employee and sort them.

in my UI, I call MyProject.Service.EmployeeService.GetActive(); in getGetActive, I call a function in PyProject.Repo to get active employee. When I have the result back (in the service method), I do an order with Linq and return the list ordered.

To resume, the Repo project, it's access DB via NHibernate and Service it's the business.

It's my opinion, it's like this I do it's may be not the best way, not the only way, but it's my way :)

like image 34
Kris-I Avatar answered Jan 02 '23 08:01

Kris-I