Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewriting NHibernate app in Linq to SQL

I have an old outdated application written using NHibernate. Now I would like to rewrite it including new functionality and big changes in model.

What are main disadvantages of using Linq to SQL instead of NHibernate ?

What are possible problems of using LINQ to SQL, does making DataContext as something like singleton can give poor performance?

like image 519
gruber Avatar asked Dec 05 '22 01:12

gruber


1 Answers

From "The false myth of encapsulating data access in the DAL":

"I would like to design a system/application using NHibernate. But I also want to so flexible that in future ,if I unplug the NHibernate and use ADO.NET Entity framework or other framework then my application should not crash."

In short, I am completely opposed for even trying doing something like that.

It is based on flawed assumptions

A lot of the drive behind this is based on the historical drive built in the time where data access layers directly accessed a database using its own dialect, resulting in the need to create just such an encapsulation in order to support multiple databases.

The issue with this drive is that it is no longer a factor, all modern OR/Ms can handle multiple databases effectively. Moreover, modern OR/M are no longer just ways to execute some SQL and get a result back, which is how old style DAL were written. An OR/M takes on a lot more responsibilities, from things like change tracking to cache management, from ensuring optimistic concurrency to managing optimal communication with the database.

And those features matter, a lot. Not only that, but they are different between each OR/M.

It doesn’t work, and you’ll find that out too late

The main problem is that no matter how hard you try, there are going to be subtle and not so subtle differences between different OR/Ms, those changes can drastically affect how you build your application.

So how do you move between OR/Ms?

There are reasons why some people want to move from one data access technology to the other. I was involved in several such efforts, and the approach that we used in each of those cases was porting, rather than trying to drop a new IDataAccess implementation.

like image 96
rebelliard Avatar answered Dec 29 '22 19:12

rebelliard