tags:

views:

360

answers:

6

Just wondering whether anyone will still use Hibernate once they move to C# 3

Are these mutually exclusive??

A: 

I dont like linq-to-sql (since that is what you mean) that much since you have to design a database schema. With hibernate (although i use a similar product named XPO) you just make your objects and the framework takes care of the relations (one-to-one, many-to-one, M-To-M).

THat is the big disadvantage of linq to sql. So no, they're not mutually exclusive.

Henri
I don't understand. I haven't use hibernate, but I know linqtosql automatically infers relations from the database schema. You don't have to set them manually.
recursive
With Hibernate also you cannot skip the step of designing the DB. Hibernate and Linq are only to query existing DBs (may be by using the DB schema)...but they do not create a schema for you.
Aayush Puri
+7  A: 

It's important to note that Linq is not just an ORM tool. There is also Linq-To-XML and Linq-To-Objects to name two but there are more. Linq is a set of language extensions to C# and VB that give you syntactic sugar when dealing with object collections.

As to your main question, Linq-to-SQL is fine if you have a one-to-one mapping from tables to domain objects. Where NHibernate comes into it's own is where you have an existing complex domain model or existing complex database schema and you want to map between them.

Additionally, it's possible to use both with Linq-To-NHibernate.

Richard Nienaber
So linq only allows you to query from one table??
ChloeRadshaw
In fact, Linq has nothing particular to do with collections at all - it's much more general. See http://stackoverflow.com/questions/1418106/how-much-is-there-to-linq/1418176#1418176
Dario
No as you can join object collections together with the join keyword. The Linq-To-Sql framework would then generate the sql join that would get sent to the server.
Richard Nienaber
Can anyone give an example of when you would use NHibernate and Linq?
ChloeRadshaw
A good example of using NHibernate and Linq would be using a generic IRepository interface that allows querying via linq. So we would use NHibernate in the implementation, but the logic that uses your repositories would use Linq.
Min
+2  A: 

Linq is more about making a uniform way in which one can query DB, XML, Objects or any custom data store. Hibernate is only for querying DBs. You can use Hibernate instead of Linq-to-SQL in case you are more proficient and comfortable in that Linq provides pretty much the same powerful ways to query DB as Hibernate. So in a way when restricting our discussion to DB, Linq can serve you the same (or a large majority of!) purpose as Hibernate.

Aayush Puri
+1  A: 

I think more people would use NHibernate if it could compete with Hibernate. That being said, NHibernate is generally not needed in a .net shop.

Woot4Moo
+1  A: 

The existance of Linq To NHibernate alone, proves not.

Peter
+1  A: 

Your terminology is off. LINQ is just syntactic sugar for manipulating data. Linq to Sql is probably what you're talking about.

IIRC Linq to Sql only supports MSSql (apparently they intentionally killed off compatability with other db providers, I have no idea why, some speculate anti-competition, others state a deadline turned up so they just culled what wasn't ready). So no chance of NHibernate being irrelevant here.
The Entity Framework (MS's ORM tool that supports all databases). When this initially came out some of the ORM community hated it, it didn't support "persistence ignorance" and a number of features, concepts and premises the community expects from a modern ORM. I believe they are working to improve it but they have a lot of catching up to do to get close to NHibernate IMO.

So no, NHibernate is still massively relevant if you want fine control over your ORM. It is one of the most flexible yet complex ORMs about and therefore still has its place.

Quibblesome