views:

8982

answers:

16

What is the concensus on when to use one of these tools adversed to the other? I find Subsonic very useful in terms of getting things done quickly, but on large projects it tends not to scale, and its ties your domain model to your database model. That is where Nhibernate comes in as it gives you lightweight POCOs that are unrelated to your database model, but the setup time is much longer.

+3  A: 

I think you pretty much nailed it. Subsonic generates code, so your business objects will be reflective of your database structure. nHibernate uses mapping files which map your business objects to the database so your objects can be structured however you like.

How large of a project is this? Will there be long term support needed? Is the cost effectiveness of Subsonic going to offset any potential scaling issues?

Bob
+10  A: 

Slightly off topic, but in a similar vein. Have you looked at Castle ActiveRecord it is written on top of NHibernate and removes the need to spend time creating XML mappings from code to the database. Like NHibernate you can structure your domain objects as you want and later generate a database schema from this structure.

Using ActiveWriter, a contributed tool, you can easily map from your database to domain objects.

FryHard
I'm playing with CAR on a pilot project now. I choose it because I like the idea of ActiveRecord on top of something as well tested as NHibernate. If I end up not liking CAR I can fall back to pure NHibernate. This gives me a safe exit - I like that. I'll try Subsonic in a few months for comparison.
tyndall
+1 never heard of activeWriter before
George Mauer
A: 

How do these compare to Linq?

Zack Peterson
LINQ itself is just a query language and not a complete data access technology. LINQ-to-SQL is a lightweight data access layer that can work as an "ORM". But I stress the lightweight part.
Joseph Daigle
+37  A: 

I'd recommend SubSonic if your project works with the ActiveRecord view that the database is your model. You'll get one class per table and everything just magically works. You can of course tweak and override things, but if you (or your project) fundamentally disagree with the class-per-table approach, I'd look at NHibernate since it starts with the more complex (but more flexible) approach of mapping your domain model to your database.

If you're using a relatively simple database that's under your control (as in, you can change columns without sending eight forms to a database division oversight review board), I'd recommend starting with SubSonic and moving to NHibernate if SubSonic doesn't meet your needs.

Jon Galloway
+3  A: 

We bootstrapped with subsonic and are now trying to evaluate if we are going to switch to nhibernate now that we are at the pain points of subsonic.

Our other option is to create some middle ground where we use subsonic to query and load up arbitrary objects with their "execute as typed list" functionality that does a name based mapping off of an arbitrary linq style sql statement. Or to try and recreate some of it in nhibernate and refactor the rest.

So I say subsonic makes sense in small apps, but maintenance on subsonic apps gets pretty hairy, we have especially hard times with overlapping validation code, and pre/post in code triggered events. For an active record pattern, subsonic is definitely 80% there, but does somethings in a flaky way, and stops you from having any real control over your inheritance hierarchy, since every class must inherit a table to get back to that table.

DevelopingChris
+6  A: 

I can't give a good comparison as I've not yet actually used NHibernate on a project, but I have used SubSonic and have been very happy with it. So far, I have not hit any major obstacles when using it.

Check out this post from Rob Conery, one of the creators of SubSonic. He talks about how to decouple your SubSonic code from the rest of the app. He even mentions the fact that this architecture would enable you to later swap out SubSonic for some other data access layer such as NHibernate or LINQ to SQL.

I know I didn't actually answer your question, but I hope this still helps.

Michael Paladino
+68  A: 

I get asked this question a lot and really it comes down to how much you want to fiddle. I can't tell you how damaging Chris Cyvas's comments RE SubSonic scaling have been - and I've been responding to these ever since :(.

The deal is - perf-wise, SubSonic scales very nicely. In terms of project growth - ANY tool you use will require your attention. Even NHibernate.

I wrote a post on how to use the Repository pattern with DI (as you would with NHIb or any tool for that matter) with SubSonic 2.1:

http://blog.wekeroad.com/blog/subsonic-writing-decoupled-testable-code-with-subsonic-2-1/

I also wrote a post on the performance of SubSOnic:

http://blog.wekeroad.com/blog/subsonic-scaling/

Hope this helps.

Rob Conery
i think someone maybe a bit biased though :p
Darren Kopp
Biased or not, I've spent the last 4 hours trying to investigate which is easier to pick up and work with and the learning curve with SubSonic seems very minimal compared to NHibernate...
RSolberg
I agree with RSolberg, you can pick up SubSonic and start banging away in a few minutes.
hminaya
+2  A: 

Again slightly off-topic, but I'll second Castle ActiveRecord - rather than using the database as your model (Subsonic approach) or spending hours in XML spaghetti (NHibernate approach) you simply place attributes on your model classes.

You can even get ActiveRecord to generate the database schema for you.

We've used this approach on quite a few projects now and the benefits are as follows:

  • Easy upgrade path to NHibernate if required in the future
  • Support for simple inheritance models - eg. Car -> Vehicle
  • The schema it generates is most likely how you would have created it anyway, so you can spend more time building the app rather than worrying about keeping your model/db in sync.
Macka
+2  A: 

Consider your team and project size when considering ActiveRecord.

In my experience, ActiveRecord is an abstraction on top of NHibernate that starts leaking like a sieve when trying more complicated scenarios.

If you have a moderately to heavily complicated or non-straightforward schema, stick with NHibernate. You can slice and dice it to near perfection.

The other place you might get into trouble is when you need a moderately complicated query. ActiveRecord hides a lot of NHibernate's implementation... but you'll need it for a complicated query, which will become very difficult if you're completely unfamiliar with HQL. Be careful team members don't just hack away at the edges instead of learning NHibernate and HQL.

ignu
+7  A: 

I wrote an article recently about .NET ORMs which has Subsonic in it, and ActiveRecord. From my experience it depends on what the project is doing, Subsonic works a lot better if you come from a SQL background but NHibernate has more ontop of it. ActiveRecord is good for smaller projects, I'm not convinced it's faster for larger projects than sticking to NHibernate.

Chris S
The link you provided is not working. Do you mean this? http://www.shrinkrays.net/articles/a-look-at-dotnet-orms.aspx
kimsk
I updated the link, thanks
Chris S
+1 Great article.
Eran Betzalel
A: 

The advice I've gotten on the topic is that Subsonic does not scale up to handle more complex scenarios and so if you go down that road you'll end up with a job trying to swap over to a more advanced ORM.

I'm thus more interested in using NHibernate for complex cases, Castle Active Record for simpler cases and am keeping an eye on Fluent NHibernate which should make NHibernate mapping a lot easier (especially once the convention based mapping support is improved).

Colin Jack
"that Subsonic does not scale up to handle more complex scenarios"The problem with this is that just saying it means nothing. There continues to be a total lack of credible evidence that SS doesn't scale. I guess it's proof that sometimes just saying something on the Internet is enough.
CarmineSantini
If you have evidence of subsonic scaling issues, please provide. I have not personally experienced any issues with SubSonic scalability.
Jim Geurts
+5  A: 

I have evaluated both and I believe it would not be fair to recommend one over the other without understanding what your goals are. In your question you stated the differences well and I believe that needs to be your deciding factor. Personally I have used both and will continue to use both depending on the project.

  • NHibernate is my choice for larger scale projects because its uses of lightweight POCO's. If I were to ever switch out my ORM "I believe" this would be much easier to refactor.
  • SubSonic is my choice when I have a smaller scale project. I believe that performance wise SubSonic scales well. However, I feel tightly coupled with it because it is so engraved in my project. In smaller project I can still switch it out because the code base is so small and it really helps me rip out code as advertised.
Jamey McElveen
A: 

Embrace the Impedance Mismatch!

check this out

:)

Or don't. If you want performance, do it yourself. If you want it quick and easy, go with NHibernate and ActiveRecord. If you like pretending that you actually know what's going on at data access level, use NHibernate and sit with XML all day long to get a many to many going... Or just... err.. do it yourself - ADO.Net FTW!

Quoo
+1 for good link to a contrarian opinion
Tom Bushell
+9  A: 

You may consider looking at Fluent NHibernate; it makes managing NHibernate a breeze. Not sure how difficult it would be to transition an existing schema, but if you're building a new application it's nice to define the domain model and generate the database in pretty much any DB server you can think of. From reading the other comments here, I think Fluent NHibernate brings NHibernate on par with SubSonic for ease of configuration.

I concur. Fluent NHibernate's automapping combined with NHibernate's SchemaExport brings all the benefits of SubSonic without any of the downside.
bingle
Fluent NHibernate is great.
Alex
+20  A: 

For what its worth...I have had the opportunity to use both technologies quite abit more since asking this question. And I have to stay which if these technologies you choose matters very little. Sure NHibernate allows your business entities to be slightly less coupled to your database structure, but I still find that there are many occasions where you still have to bend to the will of the database.

In my opinion the only true way it to totally seperate your Domain Model from your Database model is to write your own DTOS (essentially POCOs for passing data around), and then map them back to your ORM of choice in your data layer.

Dan
Excactly Dan. +2000
George Mauer
+1  A: 

I believe you should stick to one which you can utilize the best. The ultimate goal is the productivity and good performing quality code. If you know SubSonic in and out then stick to it and if you know NHibernate in depth stick to NHibernate. This is very subjective question. You should also consider the fact that what your team-member are having expertise with. If you are good at it you will be able to easily maintain it.

I've seen large projects using SubSonic whereas NHibernate is already famous and used widely.

The decision of picking ORM does not solely depend on the ORM itself.

this. __curious_geek