Wednesday, June 13, 2007

LINQ & LINQ to Entities in SQL Server 2008 "Katmai"

I am very excited with this new way to access data and recently learned something about LINQ and what SQL Server 2008 "Katmai" stores with respect to LINQ to Entities model.

Let’s have a look to...........Language Integrated Query (LINQ)

Today data can belong to different data domains like XML document, database, text file, excel spreadsheet. So various specific data access model are being used to access data from these sources. Let say XQuery is used to fetch XML data, SQL is used to query RDBMS and a custom code is written to query text files.

Now LINQ tries to resolve these issues by offering a uniform way to access and manage data. We can also see LINQ as a methodology that simplifies and unifies the implementation of any kind of data access.

LINQ consists of standard query operators
to play with data irrespective of the data sources. So in a way we are on the path to use standard code against any data source like Microsoft SQL Server, Oracle, Access or Sybase. This makes developer life really easy, so there is no need to spend hours in learning various languages (access methods) to work in multiple projects.

So precisely Microsoft is extending the power of .Net languages specifically C# and Visual Basic.Net to include this kind of functionality named as LINQ. This kind of implementation reuses the developer's existing knowledge of Object Oriented programming to play with databases, XML, objects, and few other data domains.

“Microsoft original motivation behind LINQ was to address the impedance mismatch between programming languages and database.”

LINQ to SQL (previously known as DLINQ), translates LINQ expression into SQL Server queries. People have already started creating LINQ libraries to query WMI, LDAP, SharePoint data sources.

LINQ to Entities

LINQ to Entities is supported by latest release of ADO.NET Entity Framework. The primary benefit of this framework is to run C# LINQ queries against a conceptual data model instead of tables. So LINQ to Entities seems to be a superset of DLINQ. The entity framework provides an additional layer on database schema which is available in terms of entities or conceptual model to query in .Net language.

That means writing something against entity is far more easy and manageable than writing complex SQL queries.

var CAEmployee = from employee in Employees where employeeLocation is CaliforniaState select employee;

Above statement is really easy to understand and I am really not bothered about database schema. What all I know is “employees” and I want to fetch California employees.

I guess this makes lot of sense and I really appreciate this work by Microsoft.

No comments: