tags:

views:

602

answers:

8

I'm relatively new to .NET and have being using Linq2Sql for a almost a year, but it lacks some of the features I'm looking for now.

I'm going to start a new project in which I want to use an ORM with the following characteristics:

  • It has to be very productive, I don't want to be dealing with the access layer to save or retrieve objects from or to the database, but it should allows me to easily tweak any object before actually commit it to the database; also it should allows me to work easily with a changing database schema
  • It should allows me to extend the objects mapped from the database, for example to add virtual attributes to them (virtual columns to a table)
  • It has to be (at least almost) database agnostic, it should allows me to work with different databases in a transparent way
  • It has to have not so much configuration or must be based on conventions to make it work
  • It should allows me to work with Linq

So, do you know any ORM that I could use? Thank you for your help.

EDIT I know that an option is to use NHibernate. This appears as the facto standard for enterprise level applications, but also it seems that is not very productive because its deep learning curve. In other way, I have read in some other post here in SO that it doesn't integrate well with Linq. Is all of that true?

+3  A: 

I suggest checking out NHibernate.

https://www.hibernate.org/343.html

jonnii
How does it integrates with linq?
eKek0
Check out the NHibernate.Linq project (and the rest of the NHibernate family) here : http://www.nhforge.org
Jeffrey Cameron
+3  A: 

Given your requirements, I'd suggest checking out Mindscape LightSpeed. It supports about eight or nine different databases, and is convention driven (with options for configuration), so is very easy to set up. It has a LINQ provider. It allows you to extend the classes with your own properties and methods: in particular it allows you to decouple the persistent model (the fields) from the API (the properties and methods) without breaking the convention over configuration approach.

itowlson
I've been very impressed with LightSpeed. It makes things much easier than NHibernate.
Reed Copsey
If it's convention driven, I'd be interested to see how it compares with FluentNHibernate, which is also convention driven.
Abel
Abel: Ah, sorry, I'm not sufficiently familiar with Fluent NHibernate to make that comparison. From your code sample, it looks like LightSpeed is basically automatically doing the equivalent of FNH AutoMap, with convention overrides specified using attributes or strategy objects (I believe FNH does this using expressions; is that correct?). There is a free edition of LightSpeed if you're interested in learning more and maybe writing up a more comprehensive comparison than mine!
itowlson
FluentNH does this using `Conventions`, which describe how it should behave. They can be applied globally, per table, per field or per datatype. There's room for improvement here, there could be more predefined behaviors, or it should become easier to override given behavior (it takes a full new inherited class currently, which is flexible, but not easiest, iirc).
Abel
+16  A: 
Abel
How does NHibernate integrates with Linq?
eKek0
It maps associations to Lists (or any other IEnumerable), which is what I use. But it is considered better to use Linq To NHibernate, which turns LINQ into ICriteria queries (the OO programmable NH API that maps to any SQL dialect). ICriteria can be a tad hard, this is an excellent lib to make that easier: http://www.hookedonlinq.com/LINQToNHibernate.ashx
Abel
Apologies, wrong linq, eh, link. Nhibernate Linq is now part of Nhibernate, see this post by Ayende: http://ayende.com/Blog/archive/2009/07/26/nhibernate-linq-1.0-released.aspx
Abel
PS: on your points above: it is 100% db agnostic (until the moment you inject DB specific queries), is considered very productive (esp. with Fluent and LinqNH), after a bit of exercise you get a full new db+schema+dao+dal up and running in 10 minutes, can be "based on conventions" (FluentNH again), is utterly, totally extendable (only provision is: properties that need to map to a DB table column, must be virtual properties or fields, but they can be public or private).
Abel
I expanded the code a bit to illustrate how 1-2-3 it can be to set this up ;-)
Abel
+1 For a great answer!
David Hall
Regarding fluent, when you use Fluent NHibernate you are putting configuration into code. That means you loose the ability to dynamically change the nhibernate mappings in a deployed environment to adapt to DBA changes. With Fluent, you have to recompile and redeploy. Fluent interfaces are great, but in some cases, such as with NHibernate and IoC containers, they remove one of the greatest strengths of those tools.
jrista
@jrista: good point, but the OP asked a solution to quickly set it up. Configuration *can* be in code (but doesn't need be, you can mix) and that *can* be a huge advantage (compile time type checking, all in one assembly etc). I use Fluent exclusively with IoC containers, why wouldn't that be possible? And in the end, of all tools available, you should choose the one that doesn't limit you but aids you in development and that depends per situation.
Abel
+1  A: 

Just as a follow up to some of the answers here, there is NHibernate Linq spearheaded by the unbelievably prolific Oren Eini, AKA Ayende Rahien

http://ayende.com/Blog/archive/2009/07/26/nhibernate-linq-1.0-released.aspx

Haven't used it, but it looks very impressive. Seems like at some level it could even be a replacement for LINQ for SQL.

Michael Silver
Meanwhile this has become part of the standard distro
Abel
+1  A: 

I've used Entity Framework for a couple of projects and really liked it. There admittedly were some kinks in the first version, particularly the way it dealt with foreign keys and stored procedures, but version 2, which is in beta and part of VS 2010 looks very promising.

Stefan
Hahaha. Seriously. I suggest looking at a real enterprise grade ORM - the list of what Entity Framework is missing is longer than all the answers here combined.
TomTom
A: 

Man..I'd go with the entity framework. It supports Linq. The entity framework 4.0 has major performance improvements over 3.5. It has everything that you require in your post. EF is more then a ORM it is a framework. I think nhibernate is a joke compared to the M$ entity framework. Nhibernate really dropped the ball for not including intellisense and making the setup easier.

Many enterprise organizations have embraced entity framework as well. Entity framework can support any database that can be ran on windows because it has a feature to allow any vendor to create a provider for it. Do yourself a favor and go with EF.

Luke101
Interesting, why wouldn't NHibernate have IntelliSense? NH is solely .NET and as any other .NET lib, IntelliSense supports NH. The setup can be done graphically, and the XML HBM files support IntelliSense too. But that's hardly something you should base a decision on.
Abel
-1 - seriously, nhibernate is a lot better than entity framework in basic features. Generated SQL is better, it has 2nd level caching ability. Entity Framework is still a 3rd grade ORM - at least it is usable now in 2010.
TomTom
+4  A: 

Why not look at subsonic? I like it over the others because it's lightweight maps transparently to the database scheme (uses ActiveRecord) and fulfills all your requirements.

It has to be very productive.

I think this is the job of every ORM? With subsonic you can use the Controller (for databinding) or just execute the Save method on any ORM object.

It should allows me to extend the objects

Extending the generated classes is easy, they are all defined as partials. And you can even edit the templates. (They are T4 templates you include in your project, so you have complete control over how and what is generated)

It has to be (at least allmost) database agnostic

I think this is kinda basic for any ORM. Subsonic supports a lot of database of which the well knowns are: Oracle, mySql, MsSql, SqlLite, SqlCE. You can look at the database support list here.

It has to have not so much configuration or must be based on conventions

Yes, it is absolutely convention over configuraion or opinionated as they call it. For a summary of the conventions look here.

It should allows me to work with Linq

Absolutely, since version 3.0 Linq is supported.

For a comparisson between nhibernate, LinqToSql and subsonic read this It's actually a fair and up to date comparison and explicitly outlines the differences in the visions of the different ORM's.

Things I miss in subsonic:

  • UnitOfWork support (you could solve this by using the support for transactions.)

  • IdentityMap support (your objects get cached in some scope (appdomain, threat, web request context, page lifetime, ...) Although you good argue if this is supposed to be part of the ORM, or of some caching layer.

I heard hibernate supported both.

Cohen
Not every ORM is productive and/or database agnostic. Linq2Sql is very unproductive when you have a changing database schema, or if you want to forget to save or retrieve by yourself data from or to the database. Also, Linq2Sql only works with Sql Server, so it is not database agnostic at all.
eKek0
On *"fair comparison"* : the author himself says *"I have never used NHibernate"*, the comparison itself is on subsonic.com, hardly a good starting point for being considered "fair" (I'm not saying it isn't fair, I'm just saying it looks different).
Abel
@Abel, actually admitting that is quite fair IMHO. The reason I explicitly mention "fair", is that when I read "author of x has a comparison with y, z, ..." I almost never go read it. Most of the time they are just highlighting their product. What is not the case with this comparison. He compares the fundamental differences in visions of the different ORM's, which is especially helpful if you are new to the ORM landscape.
Cohen
A: 

You could also look at LLBLGen While it lacks a snappy name, it does have all the features you mentioned:

It is drivers for most database version, Oracle and SQL and others It supports Linq, in that you can use Linq to query the LLBLgen generated objects It allows you to extend the generated objects, they are all partial classes

edosoft