Language Integrated Query (LINQ), pronounced simply as 'link' is a is a component released within the .NET 3.5 Framework. It is one of the most powerful features of .NET 3.5. It serves the purpose of querying objects.
=> LINQ to Object {Queries performed against the in-memory data}
=> LINQ to ADO.Net
* LINQ to SQL (formerly DLinq) {Queries performed against the relation database only Microsoft SQL Server Supported}
* LINQ to DataSet {Supports queries by using ADO.NET data sets and data tables}
* LINQ to Entities {Microsoft ORM solution}
=> LINQ to XML (formerly XLinq) { Queries performed against the XML source}
System.Linq.dll
using System.Data.Linq; {for fetching the records from database}
using System.Linq; {for perform conditional operation like as "orderby, groupby, where, take etc.... }
Avoid boxing and unboxing.
Data is type safe.
Example:- (Add Reference System.Data.Linq)
Microsoft basically divides LINQ into three areas and that are give below.
=> LINQ to Object {Queries performed against the in-memory data}
=> LINQ to ADO.Net
* LINQ to SQL (formerly DLinq) {Queries performed against the relation database only Microsoft SQL Server Supported}
* LINQ to DataSet {Supports queries by using ADO.NET data sets and data tables}
* LINQ to Entities {Microsoft ORM solution}
=> LINQ to XML (formerly XLinq) { Queries performed against the XML source}
There are two main dll's:-
System.Data.Linq.dllSystem.Linq.dll
Three namespace are:-
using System.Data.Linq.Mapping; {for creating entity model or entity class }using System.Data.Linq; {for fetching the records from database}
using System.Linq; {for perform conditional operation like as "orderby, groupby, where, take etc.... }
Linq features :-
Encapsulated the features of generics.Avoid boxing and unboxing.
Data is type safe.
Example:- (Add Reference System.Data.Linq)
DAL.cs
using System;
using System.Data.Linq;
public class DAL:DataContext
{
public DAL(string sCon):base(sCon)
{
}
}
BL.cs
using System;
using System.Data.Linq.Mapping;
[Table(Name="student_detail")]
public class Student
{
[Column(Name = "in_student_id", IsPrimaryKey = true)]
public int SID { get; set; }
[Column(Name = "nvc_student_name")]
public string SNAME { get; set; }
[Column(Name = "nvc_address")]
public string SADDRESS { get; set; }
[Column(Name = "nvc_contact")]
public string SCONTACT { get; set; }
[Column(Name = "nvc_email")]
public string SEMAIL { get; set; }
}
Default.aspx.cs
protected void button_Click(object sender, EventArgs e)
{
DAL oDal = new DAL("Data Source=.(localhost);Initial Catalog=testing;Integrated Security=true;");
Table<Student> otStudent = oDal.GetTable<Student>();
gv.DataSource = otStudent;
gv.DataBind();
}
Anonymous User
29-Apr-2019Thanks for sharing the informative post.
Anurag Sharma
11-Nov-2011Thanks
Uttam Misra
11-Nov-2011Anonymous User
11-Nov-2011Nice blog Gaurav,
Could you please provide some more blog on concept of LINQ
Thanks,
Gaurav Shukla
11-Nov-2011I provides as soon as possible more information.
U can visit my blog on this link....
http://dotnetcorecollection.blogspot.com/