views:

345

answers:

6

We have a great project that use NHibernate as ORM. We want to migrate to L2S or L2EF. Can we do everything that we do by NHibernate?

Do you propose us that doing this work? What is the advantages and disadvantages of this work? Are these two ORMs have common capabilities?

Note: Our project written in C#.

+5  A: 

Do you have a compelling reason to change your ORM? I would argue to not change anything since you have an existing application that works well using a good persistence framework that is well supported.

Yes, you will be able do anything you are doing currently with NHibernate with the entity framework (not so sure about LINQ to SQL though) but don't switch for the sake of the framework. That would be like switching out the tires on your car a week after you bought them - it may be exciting to have new shiny tires but at the end of the day, they're just tires. The tires you have now are just fine - perhaps there are other areas of the application that would better benefit from the time that you have allotted for this project?

Andrew Hare
Agree. As far as I know, Linq to sql and Linq to EF are not even ORM's. They are actually rather primitive alternatives to NHibernate.
Stefan Steinegger
@Stefan: Linq to SQL is not a true ORM, and not intended to be. Entity Framework 4 most certainly is. Neither are "primitive" - they are designed for specific purposes, and as a corollary, neither NHibernate Linq nor EF4 can currently hold a candle to L2S in terms of ability to write complex ad-hoc queries. As with everything else, you need to pick the right tool for the job.
Aaronaught
Entity Framework, even in V4, even with additional downloads, is not currently on feature parity with NHibernate.
Michael Maddox
@Stefan, I'll agree with your comments once NHibernate is capable of doing recursive self-joins (without having to hack, which is what I do currently). Until then, I'd say L2S and L2EF are potential alternatives, so long as Oracle is not in the mix. Otherwise, NHibernate all the way, baby!
code4life
@Michael: If NHibernate and EF4 had exactly the same feature set then there'd be no reason for both to exist. They have *different* feature sets, but to suggest that NHibernate is somehow "better" comes across as fanatical and silly. Let's stick to the topic - Andrew wrote a good answer and it doesn't need to be polluted with a bunch of flippant "my ORM is better than yours" remarks.
Aaronaught
@Aaronaught: I have no allegiance to an ORM. I thought this statement by Andrew was false: "Yes, you will be able do anything you are doing currently with NHibernate with the entity framework", especially given that the person who asked the question is using .NET 3.5.
Michael Maddox
+2  A: 

What is your reason for wanting to migrate? Does the existing solution not work? Is it a performance issue? I would recommend taking a little time making sure that you understand what the issues are, performance or otherwise, and focus on these. With the right indexes on your database and using NHibernate fetures such as batching, you might find that your issues are solved without a rewrite.

Also, look at LinqToNHibernate as a first step. The Linq syntax will be the same as what you would end up using anyway. That is the beauty of Linq.

Daniel Dyson
+5  A: 

Unless you have a really good reason to change your ORM, this will be vastly more pain than it's worth. Changing ORM is as significant a change as swapping your database provider.

There will be features in NHibernate that are not present in other ORM tools (components spring to mind immediately), so you would have to find work-around or redesign classes or table structures to compensate for the changes.

Should you do this work? I'd recommend not.

Programming Hero
+2  A: 

NHibernate allows you to implement your logic without calling the DAL all the time ("persistence ignorance"). This is possible because NH compare the instances in memory and automatically detects changes.

It has great performance features (eg. the cache, query batching, insert/update batches, lazy loading).

When using NHibernate the right way, you write your application as if there wasn't any persistency (lets say: to 80%) and still get high performance. Since Linq to Sql or EF do not provide this ability (AFAIK), I can't imagine how you can migrate a large application to that. Your code will need to call the DAL all the time, where currently it doesn't.

Stefan Steinegger
Eh... both Linq to SQL and EF have all of these features, mainly through the `IQueryable` interface and `CompiledQuery` class. Only thing that's missing is batch updates/deletes, but it's easy to implement.
Aaronaught
@Aaronaught: That is not true. Neither have a second level cache, for example. There are other examples, especially if you are taking them out of the box without additional downloads.
Michael Maddox
@Michael: Sure, but this answer didn't mention a second-level cache. I was only responding to the things he listed. Linq to SQL and EF both have: Persistence ignorance, cached queries, query batching, and lazy loading.
Aaronaught
I mean: "automatic" batching, not the ability to put queries in batches. And I mean caches in general (first level, second level, query cache). I mean all these nice features which do not influence your code at all. (Except of the fact that these stuff is *missing* in your code.)
Stefan Steinegger
@Aaronaught: I read Stefan's answer differently than you did. EF 3.5 doesn't have proxy based lazy loading (I guess you could argue for some definition of lazy loading that EF 3.5 provides support, but that's quite a stretch). I was not aware that out of the box either LinqToSql or EF 3.5 supported persistence ignorance, that's news to me - again maybe my understanding of that term differs from yours. I do believe EF 4 supports both lazy loading and persistence ignorance.
Michael Maddox
@Michael: There is no EF 3.5. Are you talking about EF 1? In that case, yes, I'm aware that it didn't support much of anything, but that's not being discussed here. The Linq to SQL `DataContext` is an `IDbConnection`-based UOW implementation and Linq to SQL classes are (or can be) POCOs. That sounds like persistence ignorance to me. And if you're saying that either Linq to SQL or EF don't support deferred loading or deferred query execution then I have to assume you've never used either one.
Aaronaught
+3  A: 

If you're going to switch I would strongly advise against using linq to sql as the future is very unclear. As far as feature differences between NHibernate and linq to entities Ayende Rahien has some blog posts regarding differences.

  1. nhibernate vs. entity framework 4.0
  2. responding to how ef is better
  3. what can ef 4.0 do that nhibernate can't

FYI: Ayende is a contributing member of the NHibernate team.

In regards to your second question. It would be hard to propose doing this work with out knowing how NHibrinate is failing you. Depending on the state and size of the product I would be very hard pressed to recommend a changing an integral piece of a application like an ORM with out very well thought out reasons.

In any case, NHibrinate is a very solid product and has a long track record in the .net open source community. Microsoft on the other hand has a history of introducing Data Access / ORM solutions and abandoning them quickly.

Aaron Carlson
I agree with you that NHibernate is a very solid product. However, you say: _"Microsoft on the other hand has a history of introducing Data Access / ORM solutions and abandoning them quickly."_. With this I don’t agree. The only data access they have 'abandoned' is LINQ to SQL. ADO.NET is still used under the hood, there is no reason to assume EF will be abandoned, Object Spaces never made it RTM, so it wouldn't be fair to call it 'abandoned'. And even with LINQ to SQL we can argue if it is abandoned. Microsoft is still making bug fixes to it, but just don’t expect new functionality.
Steven
Since .net came out Microsoft does have a history of building Data Access libraries/ ORMs and instead of building upon them they come out with something new. Effectively abandoning the previous solution. Here is my interpretation of the MS .net data access evolution : DataSets -> Typed Datasets -> Data Access Block -> Enterprise library -> Linq to Sql -> Linq to entities. Linq to entities may be a long term solution but Microsofts history does not make me confidant.
Aaron Carlson
@Steven: Even before ADO.NET there was a stream of ever changing data access stuff coming out of Microsoft: ODBC, DAO, RDO, ISAM, Jet, ADO. Some of these still live on in one way or another. ADO.NET in many ways is the one that has seemed to live the longest. I honestly have no clue if Microsoft has the patience to stick with Entity Framework or if they will move on to something different.
Michael Maddox
+2  A: 

Linq to SQL does not support anywhere near the entire feature set of NHibernate. I use Linq to SQL and think it's great, but it's intended to be used as a direct 1:1 mapping against the database. It's a bit less of a true ORM than NHibernate and more of a data access solution. Among other things, it's missing:

  • Component properties;
  • Many-to-many mappings;
  • Automapping (although the designer tools mostly make up for it);
  • Multi-platform support (Linq to SQL only really supports SQL Server and SQL CE)
  • Mapping multiple tables into a single class

Entity Framework 4 is very close to NHibernate in terms of its feature set and you should be able to do most of what you're currently able to do in NHibernate. But I whole-heartedly agree with the others advising against changing your ORM just for fun; the actual semantics are very different and you will end up going through a lot of pain and bugfix cycles.

Aaronaught