tags:

views:

293

answers:

6

I need to choose carefully .NET ORM for N-tier application. That means, the I will have the server (WCF service), which exposes the data, and client, which displays it. The ORM should support all the related serialization issues smoothly - the objects or collections of objects, or whatever must travel across process boundaries. Ideally, the usage in multiprocess environment should be the same as in single process.

The criteria are:

  1. Flexibility of db schema mapping to objects (preferred)
  2. Ease of use
  3. Free, open source (preferred)
  4. Must be suitable for N-tier (multi-process multi-domain applications)
  5. Performance
  6. Tools to integrate with Visual Studio (preferred)
  7. Testability
  8. Adoption, availability of documentation
  9. Wide range of RDBMS supported (preferred; we are using MSSQL, but I wouldn't like to be tied to it)
  10. DB agnostic - different DBs, same API
+6  A: 

Why not try NHibernate?

duffymo
+4  A: 

I would recommend Entity Framework v4. It has improved beyond dramatically since v1, and supports everything you require except being open source:

  1. EF supports a very wide variety of mappings, including TPH, TPT, and TPC. Supports POCO mapping, allowing you to keep your persistence logic separate from your domain.
  2. EF has extensive and excellent support for LINQ, providing easy to use, compile-time checked querying of your model. EF Futures components such as Code-Only simplify working with EF even more, providing a pure code, compile-time checked, fluent API for defining your model. By opting for convention over configuration, Code-Only can radically reduce your model design time, allowing you to get down to business without all the hassle of tinkering with a visual model and multiple XML mapping files.
  3. It is free as part of .NET 4. (Sorry, Open Source preference can't be met here.)
  4. EF provides an excellent N-Tier solution OOB via self-tracking entities
    • Self-tracking information uses an open xml format to transfer tracking data, so tracking support could be added to non-.NET platforms
  5. Performance of EF v4 is very good, as extensive work was done on the query generator
  6. EF provides extremely rich visual design tools, and allows extensive customization of code generation via custom T4 templates and workflows
  7. EF v4 introduced numerous interfaces, including the IObjectSet<T> and IDbSet<T> interfaces, which greatly improve the unit testability of your custom contexts
  8. EF v4 is an integral part of .NET 4 and a central component of all of Microsofts current and future data initiatives. As a part of .NET, its documentation is quite extensive: MSDN, EFDesign Blog, ADO.NET Blog, dozens of .NET and Programming sites and blogs provide a tremendous amount of documentation and support for the platform.
jrista
Without a proper designer is the EF v4 also not really that usable. The features you enlist are often only doable after editing the EDMX file. I find your point 6. especially not very convincing. But I'm biased, I know ;)
Frans Bouma
@Frans: I guess I should have expected a retort from the king of LLBLGen. I've read your blog for some time, and while I hate to say it, you have often shown a lackluster understanding of EF (and L2S and LINQ) capabilities. EF v4's designer, unlike the disaster of EF v1's designer, is considerably more flexible. The generated code is highly customizable via T4 templates. Since switching to v4, I have never had to edit the EDMX...that was a common problem with v1. Second, with Code-Only, you don't even have an EDMX file, and ANY issue that might arise because of EDMX is eliminated.
jrista
Regarding point 6, the following blog entry on the ADO.NET blog covers the use of T4 templates and Windows Workflow to customize generation: http://blogs.msdn.com/b/adonet/archive/2009/11/05/model-first-with-the-entity-framework-4.aspx
jrista
@jrista It might have slipped your radar, but llblgen pro v3 supports EF v4 (and v1) and as I wrote all that support code, I really do know a lot about it ;) Please see this video:http://weblogs.asp.net/fbouma/archive/2010/04/28/llblgen-pro-v3-0-with-entity-framework-v4-0-12m-video.aspx The EF v4 designer might work for you, I'd like to see you using it in model first with a 100+ table system. Code first is far from done, I don't consider that an argument. You seem to be fond of EF, great, but be realistic please. That's all.
Frans Bouma
+1  A: 

Another vote for EF here.

  • Very easily unit testable. You can write your own Domain Entities and have them be reasonably free of persistence awareness using POCO approach. You can then mock the database interface and test the application logic without actual database.

  • Supports LINQ so that if you write your LINQ properly, it will only translate a single SQL statement being sent to the server.

Igor Zevaka
+1  A: 

I've been using a product called LightSpeed, it works very well and seamlessly integrates into Visual Studio 2010 & 2008. I have been using it with Sqlite, however it supports numerous rdbms. It also has a very nice feature that allows you to create POCO objects that can be used with WCF, great time saver! At first I was using the free Express Edition but soon upgraded.

LightSpeed is the best high performance .NET domain modeling and O/R mapping framework available. First class LINQ support, Visual Studio 2008 & 2010 designer integration and our famous high performance core framework means you can create rich domain-driven models more quickly and easily than ever before.

Rohan West
+3  A: 

Having worked with the following:

  • NHibernate

  • LLBLGen

  • Entity Framework

  • LINQ to SQL

  • DataObjects.Net

  • OpenAccess

  • DataTables

I can most certainly say that DataTables are superior...no just kidding. All of them do have their strengths and weaknesses.

Mainly, I have found that these strengths and wekanesses are associated with the general type of ORM, which falls into the following two categories

  • Heavy-weight

    • LLBLGen, OpenAccess, Entity Framework (pre 4.0), DataObjects all fall into this category. Heavy weight ORMs typically have entities and collections that inherit from a base class specific to the ORM (ie. EntityBase). These ORMs often offer rich design time support, code generation and in depth runtime features (such as state tracking, transaction tracking, association maintanance, etc.).

    • The Pro: Easier, faster development upfront leveraging the built in API for interacting with entities themselves at runtime (ie. from LLBLGen entity.Fields["MyField"].IsChanged or entity.IsNew or entity.Fields["MyField"].DbValue

    • The Con: Heaviness and dependencies. With these ORMs, your business objects are now tied directly into the ORM API. What if you want to change to another ORM? And what's to prevent junior developers from abusing advanced features of the ORM API to fix a simple problem with a complex solution (I've seen this a ton)? Memory usage is also a big problem with these ORMs. A collection of 5,000+ entities can easily take up 100MB of RAM with some of the above ORMs. Serialization is another problem. With the heaviness of the objects, serialization can be very slow...and it probably won't work correctly deserializing on the other side of the wire (WCF or .NET remoting, etc.). Associations may end up not re-associated correctly or certain fields may not be preserved. Several of the ORMs above have built in serialization mechanisms to improve support and speed...but none that I've seen offer full support for different formats (ie. you get binary, but not json or xml serialization support).

  • Light-weight

    • LINQ to SQL, Entity Framework POCO, NHibernate (sort of) fall into this cateogry. Light-weight ORMs typically use POCOs that you can design yourself in a file in VS (of course you can use a T4 template or a code generator too).

    • The Pro: Lightweight. Keeps it simple. ORM agnostic business objects.

    • The Con: Less features, such as entity graph maintance, state tracking, etc.

Regardless of what ORM you choose, my personal preference is to stick to LINQ, and ORM independent retrieval syntax (not the ORM's own API for fetching, if it has one).

With regard to the specific ones mentioned, here are my brief thoughts: - NHibernate: Behind the times tech wise. Lots of maintainence of xml mapping files (though Fluent NHibernate does alleviate this).

  • LLBLGen: Most mature ORM I've worked with. Easy to start up a new project and get going. Best designer. VERY heavy weight. Rich VERY powerful API. Best speed I've encountered. Because it's not the new kid on the block, some of the newer features leveraging newer technology aren't implemented as well as they should be (LINQ specifically).

  • Entity Framework: POCO class in 4.0 looks promising. 3.5 doesn't have this and I wouldn't even consider it. Even in 4.0, doesn't have great LINQ support and generates poor SQL (can makes hundreds of DB queries for a single LINQ query). Designer support is poor when it comes to larger projects.

  • LINQ to SQL: Great LINQ support (better than any other except DataObjects.Net). Mediocre persistence (save/update) support. Very lightweight (POCO). Designer support is poor all around (no refresh from DB). Poor performance on advanced LINQ queries (can make hundreds of DB queries)

  • DataObjects.Net: Really great LINQ support and performance. Offers the closest thing I've seen to POCO in a heavy-weight ORM. Really new, powerful, promising technology. Very flexible.

  • OpenAccess: Haven't worked with it a ton, but it reminds me somewhat of LLBLGen, but not as feature rich or mature.

  • DataTables: No comment

JeffN825
DataTables? What do you mean? System.Data.DataTable?
Dmitry
I think you should reclassify Entity Framework POCO. It is certainly not a "light-weight" framework as you have described it. Even using POCO with EF v4, you have the full power of EF at your disposal...you lose nothing, but don't incur the hassles of a "heavy-weight" framework like LLBLGen. This is particularly true if you use Code-Only. Your description of EFv4's LINQ and SQL support is also very off...you described EFv1's SQL queries and LINQ support...EFv4's have been radically improved.
jrista
I strongly disagree about my EF description being off. I tried doing the following last week: 1. Include an Enum value in a projection. I've seen this in examples and it works in LINQ to SQL. In EF 4.0 I get an invalid cast exception. 2. A nested subquery joined on a property from the main query. LINQ to SQL works but issues one query per subquery instance), so it has very poor performance. EF 4.0 doesn't work at all. Throws exception about the nested subquery being a constant. DataObjects .Net is the only ORM I've seen execute the nested subquery scenario with good performance.
JeffN825
@ Dmitry - yes, I've seen people use them as business objects.
JeffN825
@jrista: Code-only is very immature.
Frans Bouma
I think I agree Frans...where have I heard your name before... :)...but could you elaborate?
JeffN825
To correct the record on OpenAccess, it also allows light-weight POCO-based model development and does not require specific base class implementation. Fast and more mature than tools like EF. Definitely worth a look.
Todd
@Todd: The features list indicates OpenAccess doesn't currently support POCO, could you please elaborate? I'd be very interested in checking it out, since I was looking into OpenAccess a while ago for its interesting caching layer.
JeffN825
A: 

Having used OpenAccess on several projects, I must say that it meets all the above criteria. One system I worked on was based on WCF services talking to several client types (smart, web, other WCF services, etc.) Through a layered architecture the WCF services used OpenAccess as persistence mechanism. I am especially fond of the scaling that OpenAccess performs.. The intelligent Level 2 cache (L2 cache) does a perfect job there and it is of cause distributable. Actually I wouldn't call OA heavy weight... You don't even inherit from a base class. Also it is a big plus that there are tools to perform the day-to-day developer tasks (create a new DB schema, merge schemas and so on) integrated into visual studio.

Henrik Gøttig