tags:

views:

258

answers:

9

Hi Everyone,

I'm working on a CMS as my hobby project. Because I'm not paid for it, time is not very essential and I aspire to make a well-architected system.

I have a set of business classes which are responsible for the main logic, and they are getting data from a database through interfaces, and the data provider (which sould implement an interface) can be set from configuration.

Currently I use LINQ to SQL as my data access layer, but the more I read about this topic, the more I'm convinced that I should use a more advanced ORM, because LINQ to SQL doesn't support some things that would be very good for the overall performance of the application. For example, caching and persistence. (I read that NHibernate, for example, only consults with the database if necessary, otherwise it simply gets the data from its cache. - This is good, because on average, a website doesn't get new content for days, so instead of wasting performance by reading from the database on every request, it would be just fine to serve those from a cache.)

I'm thinking about some options and would like to know what should I do about this.

  1. Write my own persistence logic for my business classes, and keep using LINQ to SQL.
  2. Use NHibernate directly, or through Castle ActiveRecord or Fluent NHibernate
  3. Use some other ORM

My favourite choice would be the second, because NHibernate is more robust than what I need, and ActiveRecord seems to hide most of the complexity. (And, by the way, I also intend to use Castle Windsor.)

The only problem is, that I couldn't find any information on the performance of these tools. I spent a few hours googling (and binging (and I was looking on this site, as well)), found quite a few articles and blog posts, but none of those said anything about performance.

Will this be better than the current solution, or should I use something quite different for the task?

Thanks in advance!

+1  A: 

Have you seen S#arpArchitecture? It's a framework based on NHibernate and ASP.NET MVC, on which you can build your application.

Well, if you intend to build everything from scratch (maybe to learn about architecture), you can take a look at S#arpArchitecture's source code to get some inspiration.

Bruno Reis
Thank you for your answer!S#arpArchitecture looks promising, but my project doesn't use ASP.NET MVC, because its logic is quite different from the MVC pattern.
Venemo
+1  A: 

Well my vote would be, before going down the ORM route, check out a fully fledged OODBMS as well.

db4Objects from Versant is definitely worth a look, its fast, its ridiculously easy to use and its quite Mature.

Edit: Note, db4Objects supports Linq as well.

Tim Jarvis
OO DBMS'es are very much overrated. If it is fast, it generally doesn't scale very well when it comes to OO DBMS solutions and grinds to a halt when cross-querying against more than 5 or so linked entities.
Wim Hollebrandse
Have you actually tried db4O ? I think you will be very pleasantly surprised, I know I was.
Tim Jarvis
No, in all fairness I haven't. Look at them before, and always seemed very much of a fad to me. I fail to see how an OO DBMS could compete with a proper RDMBS when it comes to performance for complex queries, JOINS and sub queries.If I have a spare moment, I may just take a look. Or not. ;-)
Wim Hollebrandse
Something to be aware of, is that an OODBMS is a very different animal to an RDBMS, because it is Object Oriented, you typically don't need to Join and subquery anywhere near as much as you would in a traditional RDBMS, the Object Model is the Schema...and a good (business app) object model is typically not that deep hierachically. I don't mean this as an Insult, but really, you should take more than a cursory glance at things before you publically dismiss them as a fad or overrated, Versant have been working on this for a looong time.
Tim Jarvis
+7  A: 

Linq to SQL is nice (if you won't use anything but SQL Server). Don't bother with Linq to Entities (EF). It's broken (far from matured) - on so many levels.

I'd go for NHibernate myself - great entity mapping and multiple DB platform support. And a very much tried and tested ORM.

Wim Hollebrandse
EF v4 with .NET 4 (out by March 2010) will rectify a lot of the shortcomings of EF1 - definitely worth a look
marc_s
Thank you! And what about ActiveRecord or Fluent NHibernate? Should I use those those to make NHibernate a little easier?
Venemo
Fluent NHibernate is nice if you're hung up on mapping files. When I learned nhibernate I didn't put in the XSD files for the xml schemas. I really don't have too much trouble with the XML after I started using the XSD files.That being said. Fluent NHibernate is really sweet and you should take a look at it. That also being said, Fluent NHibernate is yet another thing to learn. If you end up having trouble with nhibernate's normal mapping then use fluent.
Min
I don't really like xml-based mapping, because it doesn't throw compile-time errors when something is wrong.
Venemo
Regarding xml-based mapping, that is another area where EF v4.0 excels, as it has a custom compiler for its xml mapping files. That aside, don't underestimate the value of putting your mappings in an xml file. If you take the fluent approach, the only way to reconfigure is to recompile and redeploy. That eliminates a huge window of opportunity to fix things in production very rapidly via configuration changes, without requiring a dev to fix a code bug and redeploy.
jrista
The nhibernate mapping files are embedded resources so I believe you won't be able to do production changes. Not sure about EF. Better to fix the bug on dev, run all your tests and then deploy to avoid any unforseen problems.
Castrohenge
Well, EF v4 will be great, but EF v3.5 was quite ill when we tried to use it at the company I work for. I wouldn't bother with EF until next march.
Venemo
Also, we discussed Fluent NHibernate, but what do you think about Castle ActiveRecord?
Venemo
I think ActiveRecord violates both Single Responsibility and Separation of Concerns. Those are two of the most important architectural guidelines that, when followed, really create an easy to maintain, composable architecture. I personally recommend against it.
jrista
+1  A: 

I would agree with you in picking up the second option. Not because i know that the performance in this case is better, but because you said that you want to have a well architect-ed system. In case you use LINQ to SQL the problem you would face is that the classes you would be generating using LINQ drag and drop would be depending strongly on the schema of your database and your table structure. Anytime you make a change in your table structure you will have to regenerate the LINQ classes. This is not desirable from the point of view of a good architecture. You should consider using NHibernate with asp.net mvc. NHibernates provide you the power of mapping your business object properties with your database table fields via xml file. This adds an additional layer of abstraction where in your business entities don't directly depend on your table structure. There is a good project on codeplex that uses NHibernates. Here is the url for that project http://jscportal.codeplex.com/ . This is a very clean CMS portal built using asp.net mvc and NHibernates. Also this project will give you an idea of making a good design for your application. All the best !

Bootcamp
I like the idea of MVC, but this project of mine is based on a different one.I'll definitely check out jscportal, however.Thank you for your answer!
Venemo
+4  A: 

I would recommend Entity Framework v4.0. Unlike the first, failed flop of an attempt at an ORM with EF v1.0, the version coming out with .NET 4.0 is truly amazing. Microsoft improved EF on every level, and directly responded to input from many of the major ORM community proponents. I had some direct input via email with Microsoft on several issues with EF, including the efficiency and validity of the generated SQL, n-Tier story, and the visual designer.

The new EF is a solid ORM that provides a complete OOB story for everything from a rich visual designer with customizable code generation, efficient SQL generation, multi-tier portable types, POCO style implementation, very rich mappings between your code, conceptual model, and database schema, etc. I used to be a big proponent of nHibernate and a strong opponent of EF, but my opinion has changed since I started using VS2010/.NET 4.0 Beta 2. I highly recommend using EF v4.0 if you are working on the .NET platform.

jrista
Yeah, when .NET 4 will be final, I'll consider EF v4.Until then, the EF in .NET 3.5 is more than ridiculous.
Venemo
+1 wish I could upvote more than once! :)
marc_s
That's great to hear, just finished up a small project using EF 1.0 and there were a lot of headaches.
Graham
@Venemo: If you need something in the mean time, I would recommend nHibernate. It is a rich, mature ORM. It just lacks in the visual design department, and has lax LINQ support.
jrista
Thank you! I'm not a fan of the visual designer, anyways.
Venemo
Why the down vote? There should really be a rule that if you down vote, you have to comment why... >.>
jrista
Actually, I voted up.
Venemo
I know it wasn't you. Just another random downvote-and-run I guess.
jrista
+2  A: 

I would say that NHibernate + FluentNhibernate would get you up and running very quickly. The best thing about FluentNhibernate is that you can set it up in just a few lines and it'll automatically map your objects to your database for you.

If you want something that's a little lighter on the config you might want to check out Subsonic

lomaxx
Talking about Fluent NHibernate, what do you thing about Castle ActiveRecord?
Venemo
Castle ActiveRecord is fine, however I think fluent has a few advantages over it. First is that you can use conventions to setup your mappings. Second is that you can map your objects without having to make any changes to your class files. With active record you have to use attributes which I feel pollutes your object model somewhat.
lomaxx
This really answers some questions for me.Thank you very much!
Venemo
A: 

LLBLGen Pro is simply the best

Bob
+1  A: 

since this is project is for learning purpose use Nhibernate it is really worth the effort to learn :)

Yassir
+1  A: 

This question has been asked and answered many times before:

http://stackoverflow.com/questions/1377236/nhibernate-entity-framework-active-records-or-linq2sql/

Michael Maddox
Thank you for your answer!However, if you had read the question before posting your answer, you would know that I already searched Stack Overflow, and I think that those topics, while they're helpful, don't apply to my specific project.
Venemo
Next time, provide links in your question to what you've already read. There is very little in your question that is unique and new that hasn't been asked before. I honestly don't see why your situation is unique. It's not nice of you to imply I didn't read the question. I very much read it, multiple times.
Michael Maddox
Sorry! Next time, I'll be more careful.Thank you for your answer!
Venemo