views:

3654

answers:

6

What's the difference between LINQ to SQL and ADO.net ?

+6  A: 

ADO.NET is the underlying data access API for .NET Framework (much like JDBC in Java). It's been around since the first release of .NET.

LINQ to SQL is a data access framework built on ADO.NET and new language features that makes SQL Server data available natively in the object oriented style of programming.

Mehrdad Afshari
+1  A: 

There is a fairly large set of differences between these two technologies that cannot be really covered in a short SO post, but I'll try to cover the highlights

  • In Linq2Sql you write your queries over in memory objects. Under the hood though the code you write is translated to expression trees and is further translated to SQL at runtime where the query is actually run. In ADO.Net you directly build SQL queries which are run against the server.
  • Linq2Sql has direct language support in C# and VB.Net. ADO.Net provides support for string based query which have 0 language support other than just a raw string.
  • The language support in Linq2Sql makes queries type safe. In ADO.Net all query results must be converted to the appropriate type which essentially removes type safety checks.
JaredPar
A: 

ADO.NET is a set of class libraries that provide basic data access infrastructure on top of .NET Basic Class Libraries. It also contains basic LINQ infrastructure, such as static class of Enumerable (that provide LINQ to Object) and an interface to do basic query against relational data such as IQueryable.

LINQ to SQL is NOT a data access framework.

ADO.NET can be assumed as a data access framework, but this can be misleading, since ADO.NET is not a standalone product. ADP.NET is truly a part of .NET Framework.

LINQ to SQL is simply an implementation of LINQ to function as a data provider that connect and maps directly to SQL Server. Underneath LINQ to SQL, contains heavy usages of ADO.NET classes in System.Data.SqlClient namespace, so it's implemented on top of ADO.NET but focusing on and it's specific to accessing SQLServer.

eriawan
A: 

Also, not really sure if I am right here. But ADO.NET is allways working 'offline' with your data. I think LINQ2SQL is working online with your data.

Wim Haanstra
That is not really the case. If you use ADO.NET DataAdapter to fill a DataSet then you are working 'offline'. However with a DataReader you are as online (connected) as can be....
Dror Harari
+2  A: 

You need to start with the understanding that LINQ is Microsoft's intended paradigm for querying all sorts of structured data declaratively with one tool - think "One Ring To Rule Them All". LINQ to SQL is just the first manifestation, implemented to query relational databases.

In fact, Microsoft has a mixed message about LINQ's relationship with SQL. I think the problem is that it has become understood as a substitute for other abstraction strategies is is now often seen as a way for programmers to avoid the need to become highly skilled at SQL.

ADO.Net treats OOP as what it is, and relational data as what it is, and expects you to do each properly on its own merits.

The advantages and disadvantages of the two are open to debate. But if you agree that Microsoft's Computer Science wizards have come up with something of a uber-abstraction for structured data querying, then you'll probably want to move in this direction. There is some indication that other software product providers are willing to play along, so it may not even end up being totally proprietary, which would be a good thing.

le dorfier
A: 

What I don't understand is on one hand MS encourages the multi tier paradigm, then they release LINQ to SQL that tightly couples the data access layer and the business logic. I know this is not an answer to the original post but wanted to throw it out there anyways.

DotnetDude
Syncronicity - I was also pondering how LINQ makes coupling/cohesion harder to manage myself. Also "partial classes" seems like another undesirable complexity.
le dorfier
Syncronicity - I was also pondering how LINQ makes coupling/cohesion harder to manage myself. But it doesn't make it inevitable - you can partition things appropriately with LINQ, but to the extent that the abstraction is overgeneralized (and it is), it just makes it harder.
le dorfier