tags:

views:

3840

answers:

23

I haven't worked on a .NET project for a while (more than a year). Before I've never used an ORM for a .NET application. What are some of your takes on this? Does using one make sense? Which ones should I consider trying?

+5  A: 

One of the things i look at is design approach, top down or bottom up. This could potentially make a big difference. There are many ORM's and i am sure someone else with more experience on some others can chime in.

I also look at how fast i need to pump things out. I usually go for the fast on most things so i go with LLBLGen or Linq to SQL. LLBLGen pretty much requires a bottom up approach, but its one of my favorites, especially since Linq support was added in. It costs money though, its not a free framework.

mattlant
One thing to note is that LLBLGen is a commercial product and carries a (relatively) hefty price tag (~$250 EU per seat). For those of you where that is a sunk cost, that might be reasonable, but for most it's overkill when you have free products available that do 98% of what you need.
Jacob Proffitt
totally agree with you. But for me its a comfort thing now as i have used it for a very long time.
mattlant
One advantage to LLBLGen is that a newbie can be up and running in a couple hours. NHibernate, in comparison, has a VERY steep learning curve.
Jess
LLBLGen is the greatest ORM ever.
Noon Silk
+18  A: 

Today: LINQ to SQL. It is easy to use, saves a ton of time during development, and generally behaves nice against the database by generating (mostly) very efficient queries.

The current version of ADO.NET Entity Framework (EF) is not production ready in my opinion; too many issues both in the designer and in the run-time (e.g. initialization times, poor SQL generated by L2E, etc). The next version of EF will hopefully change that.

Update: See this related thread: http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=4107623&SiteID=1&pageid=0

KristoferA - Huagati.com
L2E is a pain in the ***. xD
Arnis L.
That "related thread" link is dead, btw.
Pretzel
Linq to SQL is a bit like the original version of Visual Basic... easy to get going and seems fantastic until you need to do something that it doesn't support. Then you're in trouble. Think long-running transactions, caching, disconnected state, etc.Go with EF4 or NHibernate
Mark
+2  A: 

As far as I can see, LINQ to SQL IS NOT an ORM. It is more like an Entity/Relations Mapper. That means what you actually get from the database is dead structs with no behavior. Furthermore LINQ to SQL is absolutely terrible to test against. So, if you are doing TDD and wants something that you actually can stub/mock away, I would recommend NHibernate or rolling your own.

kitofr
Can you back up your statements about it being terrible to TDD against? I've find LINQ to SQL easy to test.
Slace
Its trivial to wrap the data context and mock it. I do it every friggen day.
Will
Will - you don't need to mock the data context, you can just generate one on the fly and remove it when done. See: http://www.aaron-powell.com/blog.aspx?id=1125
Slace
dead structs? you ever hear of partial classes?
David B
"Will - you don't need to mock the data context, you can just generate one on the fly and remove it when done", well that's true; but then again.. it ain't unit-testing (if you believe Michael Feathers).
kitofr
"Its trivial to wrap the data context and mock it. I do it every friggen day." - Well, then I must be using some strange mocking framework, because I can only mock interfaces, and creating a stub of a datacontext is in my point not trivial.
kitofr
"dead structs? you ever hear of partial classes? ", well... ever heard of "Tell don't ask"?
kitofr
With "Partial Classes" you can definitely add behavior.
bentford
You can mock Repositories. Look up Linq-to-Sql Repository pattern.
bentford
+8  A: 

I have used SubSonic with great success on both small and large applications. Open Source and free.

I would recommend to anyone look at subsonic to watch the screencast that is linked at the top of this page. It really shows how easy it is to setup and get started: http://subsonicproject.com/setup/gettingstarted/

Espo
Does Subsonic work with non-web projects?
Martín Marconcini
@Martin yes it does. Quite well.
RandomNoob
But still - i see L2S or NHibernate as better choices. Btw, what's happening with Subsonic development? Is it active?
Arnis L.
It's still active, but seems like the speed has dropped a little:http://code.google.com/p/subsonicproject/source/list
Espo
I just watched the 5-minute demo, and it looks real sweet: http://subsonicproject.com/docs/Simple_Repo_5_Minute_DemoAny cons? I already went with NH + ActiveRecord because NH was top-voted here.
ripper234
+8  A: 

Castle ActiveRecord is the latest love of my life, built on top of NHibernate, and takes most of the grunt work away so I can focus on the business layer. My criteria for selecting something like this is a solid community, active development, and MySQL support. So far, ActiveRecord has been working out nicely.

jasondoucette
That's the one that caught my eye, but I had trouble running an app with it. It was complaining something about my NHibernate dll version. Do you know where I can find more detailed instructions on how to use it?
Vasil
You need NHibernate 1.0 Vasil (which is no longer on Sourceforge, you'll need to download it via SVN). Make sure you don't have any NHibernate 1.2 or 2.0 on your system or it'll complain. You can actually redirect 1.2 in machine.config.
Chris S
+3  A: 

It depends on your style of development. If you value designer support you'll be happiest with Linq to SQL or Entity Framework If you value domain driven design and want to decouple your domain objects from your DAL then Entity Framework isn't for you. Linq to SQL might be good enough. Or you could look ad an OSS solution.

I have worked a bit with nHibernate and Ibatis.Net. Ibatis is a more light solution and works better if you want to map to an existing database. nHibernate is more extensive and has some more community support.

I've heard Castle ActiveRecord is good. I'm not too happy with the active record pattern so I havn't tried it. But I like the nHibernate intergration. If activerecord doesn't work for you you can migrate to plain nHibernate.

Mendelt
A: 

I have lots of experience with Gentle.NET, however, Morten has dropped support due to lack of time. I still use it despite its age and for things not too big, it is better (imo) than NHibernate. Less complicated and you don't need to maintain external files.

SInce it has been abandoned, I'd recommend you look somewhere else.

note: I am writing this in case you find Gentle.NET somewhere and consider using it…

Martín Marconcini
+3  A: 

Another consideration is the database target - if you are only going to use SqlServer then I would be tempted to future proof yourself and evaluate Entity Framework (EF)

(I know there are other db providers available for EF but not all are free and some db's still are not included)

Otherwise I've had great results with NHiberate which is incredibly flexible and has a great support ecosystem (published books, forums etc)

Richard
+34  A: 

NHibernate

Matt Hinze
If only it had full LINQ support... :/
Arnis L.
why do you need linq support?
Matt Hinze
Because LINQ is awesome?
Gavin Schultz-Ohkubo
why do you need FULL linq support?
svinto
@Matt, can you elaborate on why NHibernate? Inquiring minds want to know... ;-)
Pretzel
NHibernate has very nearly full LINQ support and will have full LINQ support soon. Why NHibernate? learning curve is steep but very brief (great docs at nhforge.org), it works, it has tens of thousands of users (youre unlikely to be the 1st person to try something with it + great community support), it's been put into production many times on small and large projects, the best in the business are working on it, it's open source, extensible, extremely flexible, has tons of features including caching, search. Fluent Nhibernate. If you're using an RDBMS from .NET, it's the best option right now.
Matt Hinze
@Matt, may be it would be better if you extend your answer instead of writing a comment?:) anyway, nicely said
chester89
A: 

NHibernate is your best choice if you want an actively developed open source solution. I built our systems using Paul Wilson's O/R mapper which sadly is no longer actively developed or supported. If you're brand new to O/R mapping it's still a great way to start since you can get it running in an hour or less. We'll be moving to NHibernate in 2009; one of the benefits of O/R mapping is that this move should be somewhat painless.

I haven't played with Linq2Sql much but it isn't really an O/R mapper. I am also concerned that it will be yet another Microsoft project that meets 80% of your needs but covering the last 20% is hell.

Jamie Ide
+3  A: 

I've used LLBLGen Pro quite extensively, and really love it. I'd recommend it as a candidate to trial in your selection process.

It's capable of generating your entire entity framework and all statically-typed relations between entities directly from your database schema, and the query framework is flexible and powerful. Since everything is generated as types there's great integration with intellisense, so writing code is really easy. It also includes data adapters so you can do all the drag-and-drop programming you want to connect your database to standard gridviews, detailsviews, etc.

Stewart Johnson
+32  A: 

Not all ORMS are equal. You might not want a full-on ORM - maybe you really just want a DAL generator to avoid the CRUD nastiness. Maybe Linq to SQL would work for you if you just want to abstract away the SQL but have no problem putting the data access logic in your code.

Living with an ORM is not a zero-friction experience. You need to know what side-effects your choice will have on your code. It may constrict you in ways you don't like (say you have to inhert from a base class and can't use POCOs). It may effectively enforce a tiered architecture when maybe you don't really want one (although I can't see why you wouldn't ).

If you want a full-on, middleware-style, very complete ORM that is extensible and can be used in many different types of setting and scale and can map well to legacy databases, then go with NHibernate. Zero question. It's IMNSHO the most developed ORM for .NET today, with all due respect to some of the commercial offerings (although LLBLGen Pro is justifiably lauded - but it's a DAL generator rather than a middleware solution, and that's not my own preference).

And if your mapping needs are simple and you don't need detailed granular control over the object lifecycle, definitely consider ActiveRecord on top of NHibernate. But be aware that it has a very different idiom to NHibernate in terms of session management, despite being built on top of it, and don't confuse the two. That, as I have found out to my cost, can really screw you up :-)

DotNetGuy
A: 

NHibernate. Nothing else. Forget LINQ to SQL and ADO.NET Entity Framework. They are too intrusive. With NHibernate you can simply use POCO's from your business domain! NHibernate just rocks!

Joachim Kerschbaumer
I agree with you on Linq 2 Sql, but Entity Framework combined with the PocoAdapter http://code.msdn.microsoft.com/EFPocoAdapter is a very good option
+5  A: 

I'd second the vote for LLBL Gen Pro.

We've used it where I work for over 3 years now, against both Oracle and SQL Server and have been very impressed. Not only is it flexible and feature rich, but it generates very streamlined queries. Additionally if you have any questions their developer community is very responsive on their message forum.

I wouldn't want to develop DB apps without it.

William
+7  A: 

I would go for either LINQ or NHibernate.

LINQ has a short learning curve. There are some excellent screencasts out there, see e.g. http://www.asp.net/learn/linq-videos/.

I've been using NHibernate more and more recently. Excellent learning screencasts are available at http://www.summerofnhibernate.com/ - hats off to Steve Bohlen :-)

Rutger
+1  A: 

LINQ to SQL is nice, LINQ to entities is looking promising but not there yet. They're good for fast small projects, for larger ones I'd personally recommend

NHibernate, Subsonic or NPersist

I tried out all open source ones I could find in this article, and those were the best of the bunch. They're all decent quality, it boils down to which has the biggest community and resources if you're having to actually do it day to day and use it commercially or on a large scale.

Chris S
+9  A: 

Since nobody mentioned it yet, I just want to throw in Genome.

I have worked on a "big" successful project (multi-million, several years, >10 developers) for which we chose Genome as persistence solution.

Of course this has been some years ago, when ORM in the .NET-space was a relative new thing.

I was responsible for the data-access of the project, and Genome left a very neat impression. Today I am working a lot with Hibernate in the Java-space, and from a developer standpoint Genome seemed way more intuitive (even though it has a different architectural philosophy and therefore cant be compared directly).

Genome is a commercial product. Genome has evolved a lot. Today it claims to be fully LINQ-compliant. If I would be in a position of evaluating a ORM-solution for .NET I would definitely look at Genome again.

Another commercial product, not mentioned yet is Telerik Open Access (formerly Vanatec Open Access).

jbandi
A: 

ActiveRecord which builds on top of nHibernate. Though you should probably NOT use nHibernate alone since there is just too much redundancy with the .hbm files and such...

ActiveRecord completely abstracts away this for you...

Thomas Hansen
+2  A: 

It's not evident in your question, but if you are developing a .Net Web application and want to use ASP.NET MVC with an ORM, take a look at S#arp Architecture

It demonstrates an architecture using NHibernate and a number of complementary tools (Castle Microkernel/Windsor (for inversion of control), FluentNHibernate (to avoid XML situps)) with a large focus on Test Driven Development.

Nagyman
A: 

I recommend the new EntityOR (http://entityorm.uuuq.com):

EntityORM is a fully typed Object Relation Mapping library for .NET 2.0.

The main strength of EntityORM is the ease of use. Most ORM libraries still require a lot of type casting and other plumbing to be written, EntityORM is designed to relieve the programmer from these tedious and error-prone tasks, making it very intuitive to use.

The main features are:

* DataBase independent
* Ease for build new drivers that are independent from the EntityORM core framework (for now there is Sql Server, MySql, Oracle, PostgreSQL and Access drivers)
* Automatic mark changed for changes entities (optional)
* Automatic lazy loading (optional)
* Ease to map for an existing database with minimal effort
* All relational types are supported (One-To-One, One-To-Many, Many-To-One, Many-To-Many)
* Flexible event framework
* Conditions para load filter data into entities
* Capability to map to different table names or field names
* Default values
* Rules validation
* Autonumber
* Guid
* Generic list to managed multiple entities hidden deleted entities
* Typed entities are lazy loading with caching reducing significantly the needed for reflection
* Entity views to faster load read-only data from one ore more tables into a single flat entity
* Join conditions to join several tables in to a sigle entity view
* Generic list to managed multiple entity views
* Distinct, group, count and sum supported in entity views
Why would you chose it over NHibernate which has all these and many more features and also is tested by thousands of hours in production in many many projects?
Ray
A: 

For small projects you can use SOODA but I know enterprise applications based on that ORM :)

It's very simple to use/configure, etc.

But if you getting seriously then nothing else than NHibernate.

dario-g
+7  A: 

Try DataObjects .NET 4.0. It's fast, easy to use and powerful framework. Uses "Code-First" approach and mapping through attributes. Rather comprehensive support of LINQ.

  • Performance
  • DB Schema generation and upgrade
  • Inheritance support (3 modes)
  • Paired properties
  • etc.

It has a lot of samples and online documentation. Currently it has providers for MS SqlServer 2005+, PostgreSql 8.1+. Provider for Oracle will be completed in August.

Alexis Kochetov
Its only GPL and commercial licenses which cost money.
Ray
+1  A: 

This question is almost a year old and some of the answers are becoming bit dated.

Nobody has recommended Entity Framework, we have used EF on two major projects and it has worked well for us.

There is an initial learning curve to EF, but in our experiance no more than for nHibernate.

http://msdn.microsoft.com/en-us/library/aa697427%28VS.80%29.aspx

If you thing that EF is a bad idea, please answer another question that I have asked about what problems you have had with EF.

http://stackoverflow.com/questions/1154773/what-problems-have-you-had-with-entity-framework

Shiraz Bhaiji