Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which data framework is better for an ASP.NET MVC site - LINQ to SQL or NHibernate

We're about to embark on some ASP.NET MVC development and have been using our own entity framework for years. However we need to support more than our entity framework is capable of and so I'd like to get some opinions about using MVC with a more robust framework. We have narrowed down or choices to either NHibernate (with the Fluent APIs) or LINQ to SQL.

Which framework lends itself best to MVC style development (I know SO uses LINQ to SQL)?

If we want to support SQL Server, Oracle, MySQL - does that exclude LINQ to SQL?

like image 624
Paul Alexander Avatar asked May 29 '09 18:05

Paul Alexander


People also ask

What is the difference between ADO.NET Entity Framework and LINQ?

Entity framework is ORM Model, which used LINQ to access database, and code is autogenerated whereas Ado.net code is larger than Entity Framework. Ado.net is faster than Entity Framework. 1. ADO.Net is create bunch of data layer code, EF is not create.

What is NHibernate in asp net?

NHibernate is an actively developed, fully featured, open source object-relational mapper for the . NET framework. It is used in thousands of successful projects. It's built on top of ADO.NET and the current version is NHibernate 4.0.

Does ASP NET have an ORM?

ORM models are gaining high popularity among ASP.NET software companies in USA, as it is provides better performance, scalability, reliability and maintainability to software applications. The ORM's use is to take programmers' LINQ statements and translate them into SQL queries for ASP.NET application .


2 Answers

As someone who has just switched from LINQ to SQL to (Fluent) NHibernate, here are a few things I've noticed.

  1. LINQ to SQL took so long to figure out how to do the equivalent of a join-subclass. After many modifications, I read somewhere that it is not possible. It can only map inheritance if ALL the columns are in that same table. This is great if there are a few columns, but there are tons in my case and sub classes are parents to other sub classes and so on. Why should I put them all in one table for the sake of my ORM?

  2. NHibernate from experience has been robust (sometimes too much for small quick projects) and although familiar with it through small projects, I felt it might be too much and went the route of LINQ to SQL since I could generate a DBML file and be going within minutes.

  3. Fluent NHibernate. Takes the best of both worlds (in my case). I can map the way I want to and have my database the way I want and not have to compromise in my domain or data models. Also one word: Automapping... icing on the cake.

I would have had to go with another ORM once I found limitations and hit a few road bumps with LINQ to SQL, but Fluent NHibernate made this choice easy, and I don't think I'll leave it unless something comes around that does the job even better.

So, like Rob Scott said, the question is how are you abstracting you domain => data model? And are you starting with a domain or a database? How complex are the relationships? If you have any inheritance at all I'd say just go with a richer ORM framework and save yourself the grief.

Fluent NHibernate has some of the best documentation I've ever found and there are so much support, notes, blogs and resources it's self-hate to do anything less... IMO! I was up and running in less than 24 hours.

Oh and if your'e new to NHibernate pick up the NHibernate in Action book to help grease the wheels although there is a lot of help for that framework as well.

The best indication that a tool isn't working is when you have to WORK the tool... LINQ to SQL I was customizing, reading white papers, all sorts of madness and it refused to generate appropriate queries, right when I was tempted to modify my table and domain, I said let me give Fluent a whirl, and I'm happy I did.

Good luck to you.. Sorry for the long response; this has all been in the past five or so days, so I guess I'm still caught up :-)

like image 58
5x1llz Avatar answered Nov 08 '22 11:11

5x1llz


I've had great success using Fluent NHibernate and dependency injection (Ninject, in my case) with MVC.

It seems to me though that any mature ORM should work well with MVC. Since the nature of MVC (Model/View/Controller) separates the three concerns, any ORM should fit quite nicely into the "Model" role.

like image 23
Stuart Childs Avatar answered Nov 08 '22 12:11

Stuart Childs