tags:

views:

191

answers:

7

I am just switching from C to C# and would like to invest sometime learning database work. I am overwhelmed with the options: Linq-to-sql, ADO.NET. nHibernate, EntityFramework, plain old sql (I am used to this). Since I have only limited 'learning' hours available (about 2.5 hours per day), where should I invest my time?

I don't want to learn something that will be obsolete next month or for which no one will hire me.

If I learn EF, will this knowledge be easily transferrable to nHibernate?

Update: I decided to start with nHibernate. While EF 4.0 has fixed many shortcomings, I don't have VS2010 right now and won;t have it for another 1 year. So nHibernate is the man for now.

+2  A: 

EntityFramework is what Microsoft is showing as their proposed database technology. It incorpates a lot of what Linq-to-Sql does. I would start there along with ADO.NET. You'll encounter ADO.NET a lot as well.

Like the comment says too Linq-to-sql isn't being advanced anymore either.

http://msdn.microsoft.com/en-us/library/aa697427(VS.80).aspx#ado.netenfrmovw_topic2

Kevin
+1. Also it's worth mentioning that it seems that Linq-to-SQL won't advance in next versions and will only be backward compatible. EntityFramework will advanced in .NET 4.0 and will probably advance in the next versions.
brickner
+3  A: 

Rather than pick something you think you might be hired for, focus on EF (perhaps) as a concrete example of a solution to the ORM problem as a whole. In spite of leaning EF your future employer might be an nHibernate house, or have their own home-grown solution. Learn EF, but use that experience to learn the ins and outs of ORM.

n8wrl
Ah yes, I would definitely like something where I can transfer the experience. Thanks.
RonJ
+1  A: 

If you wish to explore Entity Framework, this series of Pluralsight videos by Julie Lerman demonstrates many of the basics you'll need to get going. As Kevin mentioned, Microsoft is putting less emphasis on LINQ-to-SQL and more on LINQ-to-EF.

SethO
This is really useful info: if MS is spending less time on LINQ-to-SQL, then I'll spend almost no time.
RonJ
I just took a look at the videos but the examples uses VS 2010. I'll look for videos using VS 2008.
RonJ
@RonJ - yes, they are all using .NET 4.0. The latest .NET release gave Entity Framework some much-needed support (some would say "teeth").
SethO
+1  A: 

NHibernate has greater flexibility in inheritance mapping, better integration with stored procs / database functions / custom SQL / triggers, support for formula properties and it just a more mature platform than EF 4.

CodeToGlory
Can I transfer the nHibernate knowledge to EF or they are not even close?
RonJ
Yes, you can transfer your NHibernate knowledge to almost any other framework. That's because NH is extremely flexible and will teach you many ways of approaching ORM problems and situations. I find that, when teaching NHibernate to juniors, they start using other ORM's in a better way than before.
Abel
+4  A: 

Personally, I think NHibernate (plus FluentNHibernate and Linq to NHibernate) lets me keep the most sanity. In real world projects, managing a single EDMX file for a large data model in Entity Framework is really painful across a large team; in NHibernate, Fluent lets you separate things across multiple C# files, or the HBM xml format allows you do use multiple XML files. The last time I used the Entity Framework, that wasn't easy unless you had separate DataContexts for each model. (If that's changed in some way recently, I apologize for my ignorance). The most difficult thing about NHibernate will probably bite you in most ORM tools in one way or another: mapping object graphs to relational models is tricky. But you get an awful lot of control over things like lazy loading, parent/child relationships, and so on; mapping by convention is also a huge win if you're using Fluent.

But you won't go broke picking the tool that Microsoft is investing in; a lot of companies didn't even seriously consider using an ORM until the Entity Framework was released. Personally, I don't really want to work for companies that defer decisions like this until their vendor finds a passable solution, but the fact is, a lot of companies do (or will) use the Entity Framework.

There's absolutely nothing wrong with using the Entity Framework, although I suspect that if you used EF in anger for a real-world project for 4 weeks, and NHibernate in anger for about 4 weeks, with multiple developers on the project, there's a good chance you'd find NHibernate simpler. In my experience, EF looks much simpler at first, but gets hairier the longer you use it. NHibernate looks and feels much harder at first, but gets simpler and more obvious the longer you use it.

JasonTrue
Thanks. I'll go with nHibernate (see my update in original question).Just one slight aside "I don't really want to work for companies that ...". Sometimes you don;t have a choice especially when the economy sucks and you have 4 mouths to feed.
RonJ
Agreed. But I've found that having defensible opinions backed by experience gives me a lot more freedom on that front than if I just chased a single vendor's tooling for my entire career (I did work for MS for 7 years; I consider myself opinionated-but-agnostic). If you're in an area with reasonably diverse options and reasonably competent, you'll still usually have a choice.
JasonTrue
+1 .. Ah, that happens when you go out in the middle of writing a post (guess we're on the same page, check my too-lengthy version of the same). Couldn't agree more. Check my post for links to some of the mentioned techniques and ideas here and further reading.
Abel
+1  A: 

(sorry for the long post ahead, but I decided to try to give a bit of background to two of the main frameworks)

I'd like to add that using a non-Microsoft technology has the advantage of creating a larger birds-eye view of the problem and prevents you from locking yourself into that .NET + Entity + SQL Server cycle (even though Entity is database agnostic).

You might consider NHibernate. It's arguably one of the most mature open source ORM frameworks available. It is fast and it is used by large and very large enterprises. There also lies its greatest weakness: NHibernate is considered to have a rather steep learning curve. If you take this path, I can recommend the excellent book "NHibernate In Action" published by Manning.

Many of the weak points of NHibernate have been taken away from two sides: best practice ORM enterprise have been implemented in the S#arp architecture (downloads at Github now), which also covers fully automated mapping from database to MVC architecture. S#arp Architecture makes complex NHibernate scenario's a breeze (but still has a steep learning curve).

On the other side is the easy-configuration part through Fluent NHibernate, which creates a "one point of maintenance" situation: just code your entity objects in C#, call Config and the database is created if it doesn't exist. Saves you a hell of a lot of time. Fluent really makes working with NHibernate as it always should've been (and actually, as EF could've been).

Note that, unless it has changed recently, that Entity Framework requires changes to the database for the stored procedures, which is why I personally rarely applied it. Also, EF does not scale too well in enterprises unless you add a lot of effort yourself. NHibernate shines when you have an existing database, need it for large enterprises, or do not want to change what you've already created (incl. triggers, SP's, constraints).

From a learning perspective: as others have said, learning EF is a good start, it is rather easy and there's ample documentation. Smaller organizations are more likely to use EF because of the ease-of-use. Medium sized to large companies are more likely to go to NHibernate (and comparable enterprise-minded mapping systems). EF is rather new, NHibernate has a long history. Both have their merits. Both work well with LINQ. Both are (very) good to understand well and find a place on your CV.

Abel
A: 

Hi,

I'm in the same boat as you, I found the Summer of NHibernate series really useful.

http://summerofnhibernate.com/

Thanks -Hem

Hem Talreja