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?
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.
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
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.
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/
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.
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.
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…
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)
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.
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.
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 :-)
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!
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.
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 :-)
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.
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).
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...
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.
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
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.
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.
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