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>

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# (49) CD (1) CI (2) CloudComputing (2) Coding (8) CQRS (1) CSS (2) Design_Pattern (7) DevOps (4) DI (3) Dotnet (10) DotnetCore (19) Entity Framework (4) ExpressJS (4) Html (4) IIS (1) Javascript (17) Jquery (8) 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