3

Basically, I have a very good knowledge of plain old SQL coming from Classic ASP programming.

Over the past couple of months, I have been learning C# and today was my first full day at MVC 3 (Razor) which I am loving!

I need to get back in to Databases and I know that writing SqlCommand everywhere is obviously outdated (although it is nice I can still do it!).

I used to go to a great usergroup as an IT Pro and the developer stuff went completely over my head, however I do remember a few things which kept coming up such as LINQ... However, that was some time ago and now the same people on Twitter are saying how out dated it is.

I have tried to do research on both and I am clueless as to what direction I should go in, or when to use one over another (if learning both is a good thing).

I am more so confused as I thought EF was a part of the .Net Framework, however, reading through the quick start guide, I had to download a component using Nuget.

... Basically I am out of my depth here and just need some honest advice of where to go!

4 Answers 4

7

You should absolutely learn Linq the language. In my project we use it only about 50% of the time to get data in or out of a database. You can just as easily use it against other sources such as XML and objects, both of which we do lots more of.

I assume you're meaning Linq To Sql. It and EF provide very similar functionality in working with databases. We currently use both in various projects. I have a strong background in SQL so I look at both and go, "Meh." I'm not completely sold on either. I don't dislike them, they're fine. But ultimately it's just getting data in or out of a database which can be done in a ton of different ways.

One thing to keep in mind is that both L2S and EF utilize code generation to create their entities. Through T4 you have the ability to do your own code generation, and have it generate your stored procs and data access layer, if you like procs better.

Where I do like L2S and EF is when you need a quick query that joins tables, that creating a stored proc might be overkill for. You can also use it to populate your POCO objects directly in the queries, which is very nice.

Personally, if it's just about getting data in or out of a database use what you know, but do learn Linq for use against other sources of data.

1
3

Hopefully this might provide some clarity.

  1. The nuget package that you downloaded was for a preview of Entity Framework 4.1. Like MVC, EF sometimes has what is called Out of Band deliveries (additional functionality provided separate from the primary .NET framework).
  2. LINQ is worth learning in general because it is useful outside of data access scenarios (e.g. PLinq for concurrent operations over sets). It can be used with EF or over objects in general.
  3. LINQ2SQL was a stop-gap framework for providing a data-access layer using the new (at the time LINQ syntax. EntityFramework is the primary data access strategy for the .NET platform going forward.
  4. It's worth learning how to use SQLCommands just so that you can understand how they work. Just like it's worth learning GDI so you know how Winforms does its magic.
2

Learn 'Entity Framework' and don't look back, not even for a second. ORM's are definitely the way things are heading these days.

Oh and google "Linq to SQL is dead" - it's not necessarily dying, but reading about why people think it's dying is worth noting.

And as far as writing plain string sql statements in your code, that's really dead.

2

In addition to what's already been mentioned: If you have a small to medium site and are just doing basic data retrieval, Linq 2 SQL should suit you just fine. Entity Framework is billed as more of an Enterprise solution. The biggest issue with Linq to SQL in my experience has been that you can't automatically refresh your data model if your database changes (EF supports this)... If you change a table, you typically have to drop that table in your L2S designer and add it back.

See LINQ to SQL vs. ADO.NET Entity Framework for a good comparison of L2S vs EF:

2
  • I would argue that even for small projects EF is alot easier to understand/use. I recently built an ajax based chat with EF and it was a breeze.
    – user19718
    Commented Mar 13, 2011 at 2:29
  • 1
    I actually found L2S easier to learn. I did learn it first, so maybe that has something to do with it. Realistically though for simple data access - the differences are fairly trivial. Commented Mar 13, 2011 at 2:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.