Hanalei, Hawaii Tuesday, February 09, 2010

ASP.NET MVC: Choosing Your Data Access Method

I've been asked a lot over the last few weeks this question: Should I use SubSonic, LinqToSql,  or  NHibernate? And I think it's probably a good idea to go over these things in a post - so here goes.

I've been asked a lot over the last few weeks this question:

Should I use SubSonic, LinqToSql,  or  NHibernate?

And I think it's probably a good idea to go over these things in a post - so here goes...

 

Which To Choose?
If you've decided to use ORM (Object-Relational Mapping), then you have some choices when it comes to toolsets. There are a lot out there - a few you can choose from are:

  • LinqToSql - Microsoft's entry into the ORM arena
  • SubSonic - my baby
  • NHibernate - a well-respected ORM tool that has been around for a long, long time (in geek years).

There are many, many others and you may have your favorite that I don't have listed here. If it's not listed, rest assured that it's because 1) I'm biased and 2) I work for Microsoft  - but feel free to list yours in the comments! The more the merrier. This is a joke by the way - I've picked these based on price and acceptance (free and wide).

If you're not familiar with ORM and you don't have a tool you swear by, the selection can be pretty hard. Let's tackle that one first.

 

If You Don't Have a Favorite ORM Tool...
Let's start out by saying you should be very aware of the "pattern" the tool uses to work with your database. Lots of terms get thrown around, and you should be familiar with them:

Domain Objects, Entities: The class-based representation of your data. If you're using the Northwind Database, for example, a Product is a "Domain Object", also (blandly) referred to as an "Entity". What's a domain?

Domain: The context in which you are using your objects. People often refer to the structure of their objects with reference to their database as their "Domain Model"

Active Record: This is what SubSonic uses (and Rails and MonoRail) for it's core data access pattern. The idea here is that every object in your domain represents a table in your database, and every instance of that object is a row in one of those tables. The instance is responsible for "persisting" it's state to some medium (usually a database). Note that the domain model doesn't need to be literal - it's just a representation of your database in code.

Repository Pattern: The idea here is that there is an intermediary layer between your objects and your DB that handles Data Access - meaning you have "dumb objects" essentially. This is basically like a translator coming to your domain party so your database (who speaks Tagalog) can speak properly to your objects (which speak Swahili).

Data Broker: A data broker handles business logic and other things, and basically binds objects on an "as-needed" basis. It also persists the objects. This is slightly different than the Repository as it can contain some business logic.

This is also referred to as the "Mom" model, as in "Mom can I have a Product Object please? And can you put this Customer object back in the freezer for me? I can't reach..."

The main differences here are how "smart" your objects are. Some people dig the simplicity of Active Record, other people don't like the idea that a DB call can be made from any layer of your application (as it can avoid any logic you have that's supposed to happen during a call to the DB).

 

So Which One?
When people ask me about ORM tools, the first thing I ask them is "in what context?" Here's what I mean:

  • Are you a contractor that is hired to work on projects with a great amount of autonomy?
  • Do you work in a large company with more than 10 developers?
  • Are you the boss?
  • Do you prototype a lot?
  • Are you in a position to educate?

The main thing to keep in mind here is that whatever tool you use, ultimately someone else will need to pick it up and use it and you're on the line for the choice. So let's start there.

 

Lifetime Considerations. Or How To Keep Your Job
One thing to keep in mind is this guideline (for better or worse - I didn't make it up, I've just witnessed it too many times):

Nobody ever got fired for using Microsoft

This is for many reasons, but in general if you select an Open Source tool, you need to be very keen on the lifetime of your project in relation to the tool your using. A lot of times this means that you should go with LinqToSql.

With regards to SubSonic - it's become quite popular, and it's "life expectancy" just grew in a nice way with me being able to work on it more with Microsoft.

Indeed this event has a lot of advantages, one of them being (among others) that I'm part of the scoping and spec discussions with respect to MVC (and other things), and as such I know very well how to fit SubSonic into the MVC picture. I also won't "plead broke" and let the project die. This is now my job, and I love it.

NHibernate has legs, and has been around for many, many years. It's pretty obvious it's not going anywhere, and a lot of people know the tool very, very well. You can almost be sure that someone on your team will be familiar with it and will have an opinion of it.

You're pretty safe with all of the tools here, however the safest bet is LinqToSql if you're worried about "project security". If not, the productivity curve might tilt away from LinqToSql, only because of learning the ins/outs of LINQ.

 

Vision and Approach. Or "Why They Made It"
Understanding why a tool was made (and the design philosophy behind it) can help a lot in terms of deciding to use it. It's important to use a tool that fits with your programming and architectural style.

SubSonic
With SubSonic, the focus was simplicity at every turn, with performance at the top of mind always. The vision we've always had in our mind (our "Mort" if you will) is you, saying "SWEET!" while you turn off your PC and go home with your work done an hour early.

To do this we rely on the concept of "Convention over Configuration" - what you do is more important than a setting in a file somewhere. This can be advantageous if you're able to set standards for your project that align with SubSonic's conventions.

LinqToSql
This toolset is not driven by convention, and instead allows for a reasonable amount of flexibility with respect to designing your domain.

Microsoft has never been in the position of "telling developers what to do" - so you won't find a lot of "prescriptive guidance" here. Instead what you will have is a very clean, easy designer, the ability to set a lot of names and override some key behaviors.

LinqToSql is built on top of LINQ, a set of extensions to C#. This makes querying fairly straightforward, however learning a new language feature can be a consideration for a team. On the other hand you'll have to learn it eventually :).

LinqToSql works in a very literal "Domain Context" - meaning that to work with your objects, you need to have your domain "instanced" in the form of a DataContext. I talk about this in more detail here.

The summary of this post is that the DataContext is a nice, transactional way to work with your database, but there is a strong conceptual difference between what you're used to with "detached data" and the web. The upside here is that you have concurrency options built in. The downside is that this presents some limitations if you want to use objects as data-transport mechanisms. In other words if you want to instance a Product, work with it, and pass it to another layer in your application to save it, there are some hurdles to jump.

 

NHibernate
Note: I have never used NHibernate, so if I get some of this wrong please leave me a comment and clarify. I'll update the post as necessary. Know that what I'm offering, if it sounds biased, comes from lack of knowledge. And bias :).

NHibernate is a port of the Hibernate Core project from Java. Given it's history and maturity level, there is a certain amount of "weight" involved with it that you'll need to get used to. This isn't a negative statement at all - it's just been around for a while and has a lot of features to it.

Getting started with NHibernate can be a bit intimidating at first, but once you ramp up you will no doubt have twice the feature set of SubSonic and LinqToSql. Features mean learning and reading - and if you like diving into an API, this is a good choice.

NHibernate also has a very large following, and members of the core team are prolific bloggers who discuss how to do things with the toolset quite often.

There's not much you can't do with NHibernate, and all in all it's probably the most comprehensive ORM tool around.

 

Performance
It may be a feature to some, but it's lifeblood to others who find themselves at the helm of a high-traffic site.

Each of these tools is very performant, but NHibernate has spent a little more time with the concepts of data-caching and lazy/eager loading than either SubSonic or LinqToSql.

Caching is a big issue, and can pretty much be handled by your application as well as your data layer - this is an architectural decision you need to make.

 

Ease Of Use
All three of these tools are fairly easy to use in terms of Entity use and Querying in general.

SubSonic
SubSonic leans heavily the concept of the "Fluent Interface" - which means when you write a query, you write it out as you would a sentence
rather than a structural object instantiation:

IDataReader rdr=new Query("Products").ExecuteReader(); 
IDataReader rdr=new Query("Products").WHERE("CategoryID",Comparison.GreaterThan,5).ExecuteReader(); 

 

You can also work with strongly-typed collections in much the same way:

ProductCollection products=new ProductCollection().Load(); 
ProductCollection products=new ProductCollection().Where("CategoryID",Comparison.GreaterThan,5).Load(); 

 

Setting up SubSonic is very straightforward: add a reference and setup the provider in your web.config, and you're all set as SubSonic will generate your code for you using a BuildProvider (and you never have to maintain the code - it's magic). You can also use a command line to generate the classes for you.

 

LinqToSql
LinqToSql has a bit of a learning curve in that you have to learn LINQ in order to use it. It's not terribly difficult, but it is a consideration. The query looks like this:

NorthwindDataContext db=new NorthwindDataContext ();

var result = from p in db.Products 
             select p;

This query returns an IQueryable<T> object, which you can enumerate over like so:

foreach(var p in result){
     //do something...
}

You can also work with the data in List<> form:

List<Northwind.Product> list=p.ToList<Northwind.Product>();

 

LinqToSql starts to bog down a bit when things get more complex (but do keep in mind you can always use a View or SP). You can indeed write some complex queries, but they usually take hours to figure out and test unless you know the API very well. Here's one in particular that grabs a customer purchase by month rollup:

            var customerOrderGroups = 
                from c in customers
                select
                    new {c.CompanyName, 
                         YearGroups =
                             from o in c.Orders
                             group o by o.OrderDate.Year into yg
                             select
                                 new {Year = yg.Key,
                                      MonthGroups = 
                                          from o in yg
                                          group o by o.OrderDate.Month into mg
                                          select new { Month = mg.Key, Orders = mg }
                                     }
                        };

 

Again, if you know LINQ this this isn't much of an issue (when I look at this query all I see is "blond... brunette... redhead..."). The main consideration here is readability - LINQ can be a challenge when it comes to this. This is mitigated, however, in that in the next 3 years or so we'll all know LINQ very well :).

 

NHibernate
Again - not very familiar so if I write something silly, do let me know.

Setting up NHibernate is probably the biggest downside of using the tool. A mapping has to be made between your database and the toolset, and in that map you can describe all sorts of ways that your domain should take shape. This is a one-time consideration (usually) so don't be dissuaded by this alone. The fact that you have this level of control over your domain map can be very very helpful later (with regards to naming, etc).

Using NHibernate is pretty straightforward. To run a query, you simply:

ICollection<Customer> customersInLondon = Repository<Customer>.FindAll(
   Where.Customer.City.Eq("London") ); 

There multitudes of ways to get data from your db using NHibernate - even the most complex queries with nested loops and joins.

There really is no comparison here between what SubSonic can do (we always say "use a View or SP for complex queries") and NHibernate. NHibernate blows SubSonic away in query deparment.

 

Summary
I hope you found this helpful, and as you probably imagined I can't come right out and tell you to pick one over the other - it's all up to you and what you're coding at the time. Besides, this post would be way too short if I just told you to use SubSonic :).

Whatever you do - know that there isn't a "right way" or "Best Practice" with regards to MVC - it's whatever fits your project, budget, and tolerance.


Chad Lee - December 14, 2007 - I found your description of the "Repository Pattern" misleading. The idea of the repository pattern is that your domain objects and hence your domain model does not have any references or logic pertaining to persistence. The domain objects do not know how to persist themselves. This allows the domain objects to focus on what they are supposed to focus on - domain logic. This in contrast to the Active Record pattern which puts persistence responsibilities along with domain logic in the domain objects themselves. The repository pattern does not leave you with "dumb" objects. They are "dumb" in the sense that they don't know how to persist themselves, but not in any other sense of the word. In fact, using the repository pattern allows you to make your domain model very rich, since your domain model is free to concentrate on just domain logic.
Robert Mao - December 14, 2007 - Great post. I am wondering will Dynamic Data (or part of it) become a choice in the future? LINQ is great, however in many cases, quickly get a basic CRUD done is so useful.
Mike Trash - December 14, 2007 - Hey this is sorta off topic but you have broken links in a previous linq to sql post. http://blog.wekeroad.com/2007/08/22/linqtosql-momma-said-knock-you-out
Geri Langlois - December 14, 2007 - I went through a couple of ORM tools before finally settling on SubSonic. With SubSonic you can do anything that sql can do. IMHO it's just as easy to learn how to write complex sql statements then it is to learn how ORM apps would have you do it. In SubSonic documentation, you recommend sp's or views for complex queries. I've had better experiences with keeping complex queries in controllers and using the QueryCommand object. As long as the queries are parameterized I don't see a problem with this approach.
josh j - December 14, 2007 - Awesome post, keep'em coming. Lots of good info - you're gonna give ScottGu a run for his money in word-to-value ratio in your blog posts if you keep this up :) thx - josh j
Rob Conery - December 14, 2007 - @Chad - Not sure how my description differs from yours - do let me know if I missed the mark here. "Dumb" might not have been the right word - but essentially that's the shorthand for objects not knowing how to "talk" to the db. @josh - SSHHHHHHHH! You tryin to get me in trouble! Scott- he was just kidding... you're the master....
Scott Peterson - December 15, 2007 - Rob: I've been looking for the right ORM toolset over the past year, and I have to say it's a lot like dating; I'm learning more about what I doesn't work for me than what does. SubSonic has a lot of promise, but with no Access provider, I'm stuck. I know that you think Access is evil (we traded comments a few months back), but I can't get away from it. I have tried the MyGeneration/DooDads combination, which works pretty well. I an currently evaluating EntitySpaces which uses MyGeneration for code generation, and that works really well. I love the hierarchical objects available when the tool reads the data relationships. EntitySpaces is database independent as long as the schema stays the same, so I like that as well. Once I get out of Access, I can just reset my provider to SQL Server, and I'm set. I also have inherited an application that requires the ability to use ASA Anywhere 9 and 10, SQL Server 2000/2005 and Oracle 10g. The application currently uses ODBC to pull this off, and mainly uses just tables to keep things simple. Here's where EntitySpaces breaks down because it doesn't have an ASA Anywhere provider. The ASA Anywhere requirement constantly throws a wrench into things. LLBLGen Pro has an ASA Anywhere provider, but the product seems more confusing than EntitySpaces. I am like you in regards to NHibernate; I've looked it over and found it has great potential, but a steeper learning curve because of all the material. I'm also lazy and don't want to create mapping files, etc. I want code and I want it quickly so I can move on to my business objects. I think there are tools to generate the mapping files automatically, but I haven't gotten into that. Well, it's late on the east coast, but I thought I'd drop in my two cents. Any advice on my three database app would be welcome. Scott
Zack Owens - December 15, 2007 - Looks like it's about time for me (and possibly others) to start trying out NHibernate for ourselves to see what it actually does (heck, maybe some of the coolness can be considered for SubSonic).
Santos Ray Victorero, II - December 15, 2007 - Very nice post!

I have been using NHibernate for some time now because it allows me to work my way "the object way"; I create the domain model, create the mappings and generate the database while testing at every step. Also creating repositories and DAOs although time consuming it is very efficient and effective.

Santos
Ikhwan Hayat - December 15, 2007 - I've been using Castle ActiveRecord, which sits on top of NHibernate. I don't use the ActiveRecord pattern tho, I use Repositories instead. Castle ActiveRecord provides me basic CRUD methods, and most importantly, free me from having to write the NHibernate XML mappings myself since we can attach attributes to properties to map it to the DB. I agree with Santos on starting with the domain model first, rather than tables. The database is the one that should be generated, not the domain objects. I wonder if Dynamic Data can work with not just Linq to SQL and Linq to Entities?
Elmar - December 15, 2007 - I am still wondering why you are comparing SubSonic to Linq to SQL. As far as I remember it only works on SQL Server and all the other mentioned ORM-Tools (incl. SubSonic) are taking a different approach. It would be much more sufficient to compare it to the ADO.NET Entity Framework which in fact shipped with 3.5 Extension Preview bits. SubSonic and EF are both related to Microsoft and while it is good to have plenty of choice it would be good to know when to use one tool or the other. I took the time to actually test-drive EF and it looks promising because of it´s Db abstraction. There is a lot of serious mapping happening behind the scenes though. Go take a look at the great overview video at http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2007/08/29/9691.aspx Personally, I like SubSonic´s current method-based query syntax much more than creating LINQ queries. It is just so much more readable. On the other hand I might not (well, I definitely am not) used to LINQ query construction. SubSonic currently lacks features and flexibility in it´s method based query construction (joins etc.) when compared to Entity Spaces and others: Entity Spaces nested 'or' query: EmployeesCollection emps = new EmployeesCollection(); EmployeesQuery q = emps.Query; q.Select(q.EmployeeID, q.FirstName, q.LastName) .Where ( q.Or(q.LastName.Like("%A%"), q.LastName.Like("%O%")), q.BirthDate.Between("1/1/1940", "1/1/2006") ) .OrderBy(q.LastName.Descending, q.FirstName.Ascending); q.Load(); Entity Spaces Joins: CustomerQuery cust = new CustomerQuery ("c"); OrderQuery order = new OrderQuery ("o"); OrderItemQuery item = new OrderItemQuery ("oi"); cust.Select(cust.CustomerName, (item.Quantity * item.UnitPrice).Sum().As("TotalSales")); cust.InnerJoin(order).On(order.CustID == cust.CustomerID); cust.InnerJoin(item).On(item.OrderID == order.OrderID); cust.GroupBy(cust.CustomerName); cust.OrderBy("TotalSales", esOrderByDirection.Descending); CustomerCollection coll = new CustomerCollection (); coll.Load(cust); The great thing about SubSonic is the convention over configuration thing plus the fact that you don´t need a separate piece of software to generate out your classes. My conclusion would be that the query tool in SubSonic needs some serious overhaul but apart from that it is much more straightforward and solution-focused than it´s "competitors". Looking forward to the next release because Rob promised to adress just this issue: "Query Tool Upgrade: Eric and I have been talking a lot about the query tool and how to make it work with LINQ. I think we have a nice scheme planned, so expect to see a new query tool as we've discussed in the past." From looking at all the great stuff that has already come out of this project this surely will be great!
Mike - December 15, 2007 - The ToList method when used with a result from a datacontext can often be called with specifying T, which makes the example even more simple. Also, I'd like to see that LINQ to SQL query expressed in SubSonic, just to make an honest comparison. I do not use SubSonic anymore, because I found that I find it easier to work with plain old domain objects. Also, I don't like some of the inconsistencies in SubSonic (in your example, I see Where() and WHERE() methods). NHibernate would be a good choice, but I can't find a visual designer that will do the mapping for me in Visual Studio, is there one? Finally based on a comment here alone, I can already say I would not be quick to use any framework that uses a method such as FirstName.Like("%A%). I think we need to realize that LINQ will be the way to query data, period. So it's not SQL, or XPath or whatever. It's just ONE syntax to rule them all. It is the future. Any tool in the .NET space will need to support it because in 3 years, LINQ to {your framework} support is just a checkbox and many teams will want that box checked before they even consider your framework.
Jeremy Skinner - December 15, 2007 - Hi Rob I think its worth mentioning that the query syntax in your sample NHibernate code is not part of the core NHibernate framework, but is generated by Ayende's NHibernate Query Generator which can be found at http://www.ayende.com/projects/downloads/nhibernate-query-generator.aspx Jeremy
J. Philip - December 15, 2007 - In favor of NHibernate: You normally have to write XML mapping between your objects and tables but: 1- The mapping schema has been designed to written by hand and is very simple and expressive, so after a day of practice you can read a mapping file and actually understand what it does without the need of a complex tool. If you create your domain classes first, NHibernate has a tool to create the mapping files. 2- Nhibernate provides xsd schema files that you can place in your VS folder to get intellisense on the mapping files. 3- There is a good tool (free visual studio add in) that can create the mapping files for you from a database. It does not handle complex mapping like inheritance, but can save you a lot of typing if you start from an existing database: http://altinoren.com/activewriter/ There is a good post from Ayende on how NHibernate scales: http://www.ayende.com/Blog/archive/2007/10/31/A-question-of-scale.aspx
Elmar - December 15, 2007 - @Mike: Very true. It´s probably going to be LINQ to Entities everywhere. --- With regards to Linq to SQL and EF: I just found an official statement about Microsoft´s data access strategy. Especially interesting is the comparison on when to use Linq to SQL and when to use the Entity Framework. http://blogs.msdn.com/data/archive/2007/04/28/microsoft-s-data-access-strategy.aspx
Don Worthley - December 15, 2007 - I've settled on SubSonic, for my projects, but http://www.nettiers.com came in a close second. It's up there with NHibernate when it comes to complexity and learning curve, but it makes use of the Enterprise Library extensively (I know, some will find this a plus and some a serious downside), generates a nice starter suite of nUnit and VSTS tests for you as well as an admin interface and sprocs (but only if you want this stuff). It does use CodeSmith for code generation, but the version required for .netTiers is nearly free in the grand scheme of things.

One thing I really liked about the .netTiers architecture was the built in support for a workflow pipeline which allows you to abstract business rules in a pluggable fashion.

The one thing I don't have a feel for regarding .netTiers is the size of the community. Maybe someone else with experience using this ORM can share their experience and let us know how large the community is.
Paraag kantharia - December 15, 2007 - Hi Rob, Very good informative blog indeed. I am curious to know one step ahead, since after few months DLR would be the preferred way for other dynamic languages to enter .net world. As per John Lam, the person behind IronRuby... He says..." My mission would not be complete, if i cannot run Ruby on rails with Iron Ruby ". I want to make Ruby as Class 1 language for DLR. Ok great move by MS for porting all other good languages to DLR. But the question that arises is... " How will IronRuby run Ruby on rails on DLR without Active Record....? (1) Will they develop new Active Record type tool that runs only on DLR. (2) Will they utilize SubSonic in a different way, that runs as totally Active Record Solution for DLR. (3) Ruby On Rails is also an MVC... Will IronRuby create a different Ruby on rails MVC for DLR. that supports SubSonic... OK... it sounds to early now... But worth thinking whats going to happen in future. SilverLight 2.0 is based on DLR and arrives almost in March 2008, so my question is only 3 months ahead not very far... Hope i am able to clarify few things. Thanks
Rob Conery - December 15, 2007 - @Paraag: Rails is simply a stack that runs on Rubyw.exe - in other words a bunch of scripted commands that live in a directory. The thing here is that the Rails app is handled (as of now) by Rubyw.exe (through CGI). The thing Jon is making is (essentially) a replacement for Rubyw.exe - so in essence a Rails app should be "droppable" onto the DLR. Now I've never played with IronRuby - this is just what I'm guessing at. If I'm wrong - someone out there lemme know cause my whole thought here is you can still do Rails - just execute it (5 times faster) using the DLR.
Zinahe - December 16, 2007 - I know you're very busy and all. But please please have a deeper look in to NHibernate. Who knows, may be you'll learn something out of it. Or May be you'll contribute something good to it. By the way, there is a lot of convention over configuration in NHibernate too.
ESICO - December 16, 2007 - @Elmar
It sounds to me that MS bets on every data access technologie available. Even on SubSonic or at big least parts of it. The reason behind this is to stay on top of dev things and thus keep developers binded to the MS platform. I hope subsonic keeps it compatibility with Mono. And no i'm not anti-MS but I don't love/need them either.
Brian Bannister - December 16, 2007 - I can't comment on Linq and SubSonic. I have used NHibernate, NetTiers and Castle's ActiveRecord (you refer to the MonoRail part of the CastleProject).

I found ActiveRecord to be fine for prototyping but unworkable on large scale projects due to its reliance on NHibernate for documentation and underlying impletmentation. You really need to have a strong understanding of NHibernate before you start to use ActiveRecord.

I found NHibernate to have a very steep learning curve and again to be fine for prototyping but becoming unworkable for larger scale projects. We had problems with transactions behaving unintuitively and the mismatch between the lifecycle of NHibernate entities and the lifecycle of WebForms.

NetTiers just works. It's a code generator that relies on CodeSmith. The NetTiers templates are open source and fairly easy to modify. It took me a while to accept that code generation was going to work for us, but it does have strong advantages. Plus the NetTiers development community are very open to change and user contributions.

The NetTiers documentation is ok, but when you generate your code you also generate a fully functional administration site for your database with pages for every table. The generated code works straight out of the box and gives you a really good place to go when you are looking for examples of how to do things.

NetTiers is not perfect, but it is the best solution that we have found for an easy to use and understand ORM.
Tuna Toksoz - December 17, 2007 - Ayende(Oren Eini) has also been working on Linq to Nhibernate, which can be found at
https://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools/experiments/NHibernate.Linq

It combines the power of nhibernate with the simplicity of linq.
Jacob Mesu - December 17, 2007 - And one ORM that should be mentioned is the LLBLGenPro (http://www.llblgen.com/defaultgeneric.aspx) which is certainly one of the popular OR mappers in the market. You can both generate entities based on the data model and create new entities and map them to the database.
Elmar - December 17, 2007 - Sure, there are tons of good ORMs out there. We can probably rest assured that all of them cover what 98% off us developers need in their daily work. Different approaches, similar results. So it is basically just a matter of what gets you there fasted (or most comfortable ;-). Because this blog is somewhat SubSonic-centric I would have loved to learn more on the announced new query approaches - featuring LINQ wrappers and such. I think SubSonic doesn´t necessarily compete with LinqToSQL or even ADO.NET EF but can make good use of the these concepts and incorporate them in SubSonic. For example ADO.NET EF mapping is done via some simple structured xml-docs and what you get for free is Database-independence, LINQ to Entities and ESQL support in a standard Microsoft Technology. On the other hand that could overkill for SubSonic and the creators are more comfortable with ActiveRecord. Dunno, just wanted to get the discussion started ;-).
Stephan - December 17, 2007 - I've used nhibernate a lot in the past and my recent projects have all been subsonic based. I love the simplicity and quick setup. It really increases productivity. Having said that, I'd love to see some templates for subsonic that aren't active record but domain driven design (or repository) based. I don't see why this whole convention over configuration idea couldn't be applied to that pattern. I just don't like the idea that my frontend coders can access the database. I want to pass pure domain objects across service boundaries. That's my major gripe right now with subsonic. The templates are a little messy. The controller classes seem pointless to me if I still have CRUD stuff in the collection and domain objects. Simply loading a collection can be done in too many ways which have some overlap. It's not exactly intuitive. On reread this looks really negative but it's not meant that way. I'm a fan! really:)
W&ouml;chentliche Rundablage: ASP.NET MVC, ADO.NET Dataservices (&quot;Astoria&quot;), ASP.NET, LINQ, WPF | Code-Inside Blog - December 17, 2007 - [...] ASP.NET MVC: Choosing Your Data Access Method [...]
Todd - December 18, 2007 - Rob, Great post. I liked the Matrix reference when you discussed the LinqToSql code, very funny.
Matt Blodgett - December 18, 2007 - Great post, Rob. I wish I had this six months ago.
Ben - December 18, 2007 - I've settled on Subsonic.
-It allows you to get up and running almost instantly
-95% of my data fetching code is done using one line of SubSonic code.
-amount of required typing (on the keyboard) is minimized
-I spend NO time in wizards and configuration files

I stress this point, 95% of all my CRUD is allready done 2 minutes after adding the subsonic reference to my project.

-Ben
Dmitriy Nagirnyak - December 18, 2007 - Interesting post. And it's nice to see that you, Rob, are giving your opinion on these tools and don't saying "my one is the best" :) Which might true, of course :) I have used Enterprise Core Objects (ECO) Framework and is very very happy with it. http://www.capableobjects.com/products/ecoiv It is implementation of Model Driven Architecture which allows UML-designing the application and persist it in the DB. The O/R mapper is only small part of it. Some of its features: * Maintaining your business classes and relationships as UML diagrams. * UML state diagram execution. * In-memory transactions. * Multiple undo/redo support. * OCL expression evaluation (like HQL). * Quick application prototyping (Design and run so called "debugger" with no configuration to test). * Multi-user synchronization. * Automatic creation and modification of your database schema. * Custom mapping to existing databases via XML mapping information (by default created internally and not "visible" until needed). * Support for updating multiple databases. * Different databases support. * Reusing business classes (UML packages) across multiple applications. * Delayed and lazy fetch. * In-memory data caching. It allows completely abstract from Database and always use the business objects. Lots of "ECO services" are described in the zipped PDF: http://myecospace.net/Eco3Services.zip It can be easily picked by new developers and is highly customizable. The biggest disadvantage of it - it doesn't always generate "optimal" SQL. But it is probably the case with any O/R mapper tools. Regards, Dmitriy.
Rob Conery ASP.NET MVC: Choosing Your Data Access Method &laquo; Noocyte&#8217;s Weblog - December 21, 2007 - [...] Link to Rob Conery » ASP.NET MVC: Choosing Your Data Access Method [...]
Sergey - December 27, 2007 - I am just curious what data access method you had used in your projects before SubSonic emerged?

Serg
Roger Jennings - January 1, 2008 - Pingback from http://oakleafblog.blogspot.com/2007/12/link-and-entity-framework-posts-for_31.html (Better late than never) --rj
Gecko