Funding for 'IT Lab' Project, Phase 1: Progress of sticker sales. Purchase a sticker to help us reach our target.Updated: 2010-02-28 11:53
10.7%
LINQ


by Eranda Niroshan



One of the Latest Technologies introduced by Microsoft, yes I am talking about LINQ. Still most of the people don’t know what it is and what it can do. LINQ stands for “Language Integrated Query.” LINQ fundamentally is about integrating query operations into the .NET platform in a full and open method. It’s also about providing a joined way for you to query across any kind of data that you have in your program(database , XML , Array , etc…). The possibilities of having query capabilities were always available for any language came with .net environment at your fingertips, regardless of the type of data you’re working with.

 The core of LINQ is a set of API with interfaces and classes. These API patterns specify how an object model can become “queryable,” and they cover all the basic query operations that we know: projection (select), filter (where), grouping (group by), ordering (order by), joining (join), etc. By implementing this API pattern, any data provider on .NET can become queryable.

                                                               

 Basically the architecture of the Language Integrated Query is divided into three main categories LINQ to Object, LINQ to ADO.Net and LINQ to XML. Because of that reason it’s easy to understand and implement. Nowadays lots of .net applications use LINQ to establish connections between their back end and front end.

 Inside the LINQ to ADO.Net there are three separate Query (LINQ) technologies: LINQ to DataSet, LINQ to SQL, and LINQ to Entities. LINQ to DataSet provides vast, controlled querying over the typical .Net DataSets, LINQ to SQL enables you to access SQL Server databases through Object oriented manner, and LINQ to Entities allows you to query an Entity Data Model.


LINQ to Dataset

When we are dealing with ADO.Net, Dataset is the most primitive component, and it is a key element of writing programming codes over databases. However, the DataSet has limited query capabilities. LINQ to DataSet enables you to query into DataSet by using the same query functionality that is used for many other data sources.

 
LINQ to SQL
(formerly DLinq)

       LINQ to SQL maps relational schema into Object oriented model expressed in the programming language. Therefore it is easy to write and execute queries rather than passing String type queries into the sqlcommand object. When you execute the application, LINQ to SQL translates language-integrated queries in the object model into SQL and sends them to the database for execution. When the database returns the results, LINQ to SQL translates them back into objects that programmers can manipulate.

     

       LINQ to ENtities

         Through the Entity Data Model, relational data is represented as objects in the .NET environment. This allows developers to build queries against the database from the language used to build the business logic. This capability is known as LINQ to Entities.

         Following examples show how to implement LINQ solutions against typical .Net solutions

                          1. find maximum number of an integer array

                                        

                                                                    

                                   Normal solution

       

            int[]arr = { 7 ,2 ,3 ,9 ,5 ,8 ,1 ,4 ,6 ,10 };

            Console.WriteLine( arr.Max().ToString() )

                                               
                                                      
LINQ solution
                       

                    2. Get Customer details from Customers Table and print them into the standard output

                                        

                                                   ADO.Net Solution

 

              /*assume that db is the object represent connection with database*/

              var cust = from c in db.Customers where c.tot_trnsc_amt > 10000

                     select c;

              foreach (var c in cust)

               {

        Console.Write(c.name);

                         }
                                                           LINQ Solution

  There are lots of advantages in Language–Integrated Query, by looking at previous examples you can see number of code lines has been reduced greatly. To develop an database related application in C# or VB.Net, developer must have good knowledge of object oriented concept as well as SQL, so it means developer must be familiar with both technologies to develop an application. In the second example you can see SQL statements has become part of the C# code, therefore programmers who are very much familiar with databases also can develop applications without difficulty. Another advantage of LINQ is you can use one syntax type instead of using different programming syntaxes.


Relational data

SQL

XML documents

XPath

.NET objects

.NET built-in operators (foreach...)

Relational data

                       LINQ

XML documents

.NET objects

This is the basic introduction about the Language Integrated Query and its functionalities. If you want to learn more about it please refer MSDN.


http://msdn.microsoft.com/en-us/netframework/aa904594.aspx


Share/Save
No votes yet

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options