Thursday, 23 May 2013

LINQ

LINQ is a technique for querying data from any Datasource. data source could be the collections of objects, database or XML files. We can easily retrieve data from any object that implements the IEnumerable<T> interface.

Advantages:  as Linq Queries is integrated with .net c# language , it enables you to write code much faster then than if you were writing oldstyle queries. In some cases I have seen, by using LINQ development time cut in half.

Microsoft basically divides LINQ into three areas and that are give below.
  1. LINQ to Object {Queries performed against the in-memory data}
  2. LINQ to ADO.Net
    A- LINQ to SQL (formerly DLinq) {Queries performed against the relation database only Microsoft SQL Server Supported}
    B- LINQ to DataSet {Supports queries by using ADO.NET data sets and data tables}
    C- LINQ to Entities {Microsoft ORM solution}
  3. LINQ to XML (formerly XLinq) { Queries performed against the XML source}
now we write some code snippet of LINQ.

int[] nums = new int[] {0,1,2};

var res = from a in nums
             where a < 3
             orderby a
             select a;

foreach(int i in res)
    Console.WriteLine(i);

Output:
0
1
2

Return type of Linq
its depends on the select operation.
If you are querying a database(Linq to SQL) then the return type is IQueryable<T> where T is Product in below
var product = from p in dbContext.Products
             
select p;
If you are using Linq againist a datasource which is an Enumerable collection(List) then the return type will be IEnumerable<t>

Related Posts:

  • IEnumerable vs IQueryable Many  developers gets confused between IEnumerable and IQueryable. When it comes to writing code, both looks very similar. However the… Read More
  • Ordering data in LINQ queries by more than one column In this post, I am going to show how to do ordering when you require to order data by using multiple columns.By using .Orderby(x=>x.Columnname) i… Read More
  • LINQ vs Stored Procedure Comparing LINQ with Stored ProcedureLINQ provide you common query syntax to query various data sources like SQL Server, Oracle, DB2, WebServices, XML… Read More
  • LINQ/LAMBDA Query Example How to get the Value of attribute from XML using XDocument class string inputXml = @"<?xml version='1.0' encoding='UTF-8'… Read More
  • LINQ LINQ is a technique for querying data from any Datasource. data source could be the collections of objects, database or XML files. We can easily retr… Read More

0 comments:

Post a Comment

Topics

ADFS (1) ADO .Net (1) Ajax (1) Angular (47) Angular Js (15) ASP .Net (14) Authentication (4) Azure (3) Breeze.js (1) C# (55) CD (1) CI (2) CloudComputing (2) Coding (10) CQRS (1) CSS (2) Design_Pattern (7) DevOps (4) DI (3) Dotnet (10) DotnetCore (20) Entity Framework (5) ExpressJS (4) Html (4) IIS (1) Javascript (17) Jquery (8) jwtToken (4) Lamda (3) Linq (10) microservice (4) Mongodb (1) MVC (46) NodeJS (8) React (10) SDLC (1) Sql Server (32) SSIS (3) SSO (1) TypeScript (3) UI (1) UnitTest (2) WCF (14) Web Api (16) Web Service (1) XMl (1)

Dotnet Guru Archives