Saqib Ullah

BootStrapper Know How

  Home  |   Contact  |   Syndication    |   Login
  109 Posts | 1 Stories | 818 Comments | 15 Trackbacks

News



Article Categories

Archives

Post Categories

Blogging websites

Favourite Blogs

Private Links

Sites

Microsoft Babies
Microsoft new baby yes I am talking about LINQ stand for Language-Integrated Query is now available as a integral part of Visual Studio Orcas. Microsoft releases the new Visual Studio with the name of Orcas and all Microsoft previous efforts (Windows Communication Foundation WCF, Windows Workflow Foundation WWF, Windows Presentation Foundation WPF, Windows CardSpace and LINQ) are integrated in this Studio. From last one and half years Anders Hejlsberg team done a tremendous job in the overcoming the gap between the data impedance. Mr. Anders team gives a native syntax to developers in the form LINQ to C# and VB.Net for accessing data from any repository. The repository could be in memory object, database (still MS SQL Server only) and XML files.
 
What is LINQ?
Still lots of folks don’t understand what LINQ is doing. Basically LINQ address the current database development model in the context of Object Oriented Programming Model. If some one wants to develop database application on .Net platform the very simple approach he uses ADO.Net. ADO.Net is serving as middle ware in application and provides complete object oriented wrapper around the database SQL. Developing application in C# and VB.Net so 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. If here I can say SQL statements are become part of the C# and VB.Net code so it’s not mistaken in form of LINQ. According to Anders Hejlsberg the chief architect of C#.
 
             “Microsoft original motivation behind LINQ was to address the impedance mismatch between programming languages and database.”
 
LINQ has a great power of querying on any source of data, 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. 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}
 
I hope few above lines increase your concrete knowledge about Microsoft LINQ and now we write some code snippet of LINQ.
 
1. Code Snippet

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
 
 
All SQL Operates are available in LINQ to Object like Sum Operator in the following code.
 
2. Code Snippet

int[] nums = new int[] {2,4,6,2};
int result = nums.Sum();
Console.WriteLine(result);

Output:
1
2

One thing that I want to share with you guys is LINQ to Object support querying against any object that inherits from IEnumerable (all .Net collection inherits from IEnumerable interface). LINQ to Object provided main types of Operator Type that are give below.
 
 

Operator Types
Operator Name
Aggregation
  • Aggregate
  • Average
  • Count
  • LongCount,
  • Max,
  • Min,
  • Sum
Conversion
  • Cast,
  • OfType,
  • ToArray,
  • ToDictionary,
  • ToList,
  • ToLookup,
  • ToSequence
Element
  • DefaultIfEmpty,
  • ElementAt,
  • ElementAtOrDefault,
  • First,
  • FirstOrDefault,
  • Last,
  • LastOrDefault,
  • Single,
  • SingleOrDefault
Equality
  • EqualAll
Generation
  • Empty,
  • Range,
  • Repeat
Grouping
  • GroupBy
Joining
  • GroupJoin,
  • Join
Ordering
  • OrderBy,
  • ThenBy,
  • OrderByDescending,
  • ThenByDescending,
  • Reverse
Partitioning
  • Skip,
  • SkipWhile,
  •  Take,
  •  TakeWhile
Quantifiers
  • All,
  • Any,
  • Contains
Restriction
  • Where
Selection
  • Select,
  • SelectMany
Set
  • Concat,
  • Distinct,
  • Except,
  • Intersect,
  • Union
 
To the good use of above operator types I need samle patient class so here it

using System;
 
public class Patient
{
    // Fields
    private string _name;
    private int _age;
    private string _gender;
    private string _area;
    // Properties
    public string PatientName
    {
        get { return _name; }
        set { _name = value; }
    }
 
    public string Area
    {
        get { return _area; }
        set { _area = value; }
    }
    public String Gender
    {
        get { return _gender; }
        set { _gender = value; }
    }
    public int Age
    {
        get { return _age; }
        set { _age = value; }
    }
}
 
Here is my code that intiliaze patients object with following data.
 

List<Patient> patients = new List<Patient> {
           new Patient { PatientName="Ali Khan", Age=20, Gender="Male" , Area = "Gulshan"},
           new Patient { PatientName="Ahmed Siddiqui", Age=25 ,Gender="Male", Area = "NorthKarachi" },
           new Patient { PatientName="Nida Ali", Age=20, Gender="Female", Area = "NorthNazimabad"},
           new Patient { PatientName="Sana Khan", Age=18, Gender="Female", Area = "NorthNazimabad"},
           new Patient { PatientName="Shahbaz Khan", Age=19, Gender="Male", Area = "Gulshan"},
           new Patient { PatientName="Noman Altaf", Age=19, Gender="Male", Area = "Gulshan"},
           new Patient { PatientName="Uzma Shah", Age=23, Gender="Female", Area = "NorthKarachi"}};
 
Patient p = new Patient();
        p.Age =33; p.Gender = "male";
        p.PatientName = "Hammad Ali"
        p.Area = "Defence";         
        patients.Add(p);
 
I have been written a blog on the new way of initilaztion.

This code snippet fetch those records whose gender is equal to “Male”.
 

   gdView.DataSource = from pa in patients
                        where pa.Gender == "Male"
                        orderby pa.PatientName, pa.Gender, pa.Age
                        select pa;
   gdView.DataBind();
 
The following code snippet uses the selection operator type, which brings all those records whose age is more than 20 years.

 var mypatient = from pa in patients
                  where pa.Age > 20
                  orderby pa.PatientName, pa.Gender, pa.Age
                  select pa;
       
        foreach(var pp in mypatient)
        {
        Debug.WriteLine(pp.PatientName + " "+ pp.Age + " " +          pp.Gender);
        }
 The following code snippet uses the grouping operator type that group patient data on the bases area. 

var op = from pa in patients
group pa by pa.Area into g
select new {area = g.Key, count = g.Count(), allpatient = g};
 
 foreach(var g in op)
 {
    Debug.WriteLine(g.count+ "," + g.area);
    foreach(var l in g.allpatient)
     {
       Debug.WriteLine("\t"+l.PatientName);
     }
 }
This code snippet determine the count of those records, which lay in above 20 years. 

int patientCount = (from pa in patients
                    where pa.Age > 20
                    orderby pa.PatientName, pa.Gender, pa.Age
                    select pa).Count();

All the above codes are few example of LINQ to Object technique of LINQ. In my up coming post you will see both LINQ to SQL and LINQ to XML code snippets.
 
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted on Monday, April 30, 2007 9:51 AM

Feedback

# re: What is LINQ? 8/24/2007 8:44 AM Rakesh Nandrajog
This is really nice topic to gives a hats off to LINQ

# Nice article 9/8/2007 4:02 PM Yohan Liyanage
Very Good article which gives a good starting introduction into Microsoft LINQ.

Thanks Saqib!

# re: What is LINQ? 9/10/2007 1:39 AM Sandip Maniar
Nice article to get an overview about MS LINQ.

Thanks

# re: What is LINQ? 10/31/2007 5:24 PM Charlie
I think LINQ is a little strange

# re: What is LINQ? 12/2/2007 8:56 PM ARTI
I didnot know anything about LINQ.

Now on reading this article , i understand what is linq.
Thank you.

# re: What is LINQ? 12/12/2007 10:07 PM Gopz
PLS GIVE ME A LINK WHICH EXPLAINS CLEARLY ABOUR LINQ

# re: What is LINQ? 12/18/2007 1:53 AM Matt
How in the heck does the sum() in snippet #2 output 1,2 ??

# re: What is LINQ? 12/19/2007 7:19 PM Diwakar Gautam
Reallly Nice Article.

Hope for Some Others

Thanks.

Diwakar

# re: What is LINQ? 12/26/2007 1:45 PM subhash nayak
The above description about LINQ that deals with in-memory objects. How do we use LINQ to access databse??
Thanks and regds
Subhash

# re: What is LINQ? 12/26/2007 4:42 PM Roshan Perera
A very good introduction to LINQ

Thanks

Roshan

# re: What is LINQ? 12/30/2007 6:27 PM suyog.kale
very good article on Microsoft new baby :: LINQ,
really helping me , must be .net deveopers also
Thanks & Rgds,
************************************************************
Suyog Kale
Software Programmer
SpadeWorx Software Services
302, Sai APEX, Dutta Mandir Chowk, Viman Nagar, Pune - 411 014, India

DID : +91-204-010-0506
Mobile : +91-98600-22-945
email : suyog.kale@spadeworx.com
web : www.spadeworx.com
web : www.ormux.com
************************************************************


# re: What is LINQ? 12/30/2007 6:38 PM suyog.kale
very good article on Microsoft new baby :: LINQ,
really helping me , must be .net developers also
Thanks & Rgds,
************************************************************
Suyog Kale
Software Programmer
SpadeWorx Software Services
302, Sai APEX, Dutta Mandir Chowk, Viman Nagar, Pune - 411 014, India

DID : +91-204-010-0506
Mobile : +91-98600-22-945
email : suyog.kale@spadeworx.com
web : www.spadeworx.com
web : www.ormux.com
************************************************************

# re: What is LINQ? 1/1/2008 7:24 PM Vivek uprit
its a realy ultimate topic on LINQ and thanks to the team of microsoft to provide such a nice concept


# re: What is LINQ? 1/8/2008 9:59 PM Vijay KUmar
GOOD ONE... Its Give the Basic Idea About LINQ But .. may can give Detailed Example THat might Help Lot of New Users of .Net 2008

# re: What is LINQ? 1/11/2008 12:05 AM Hemant Ahire
Its really a nice stuff...
addressing the basic role of LINQ.
Lot of Thanks

# re: What is LINQ? 1/18/2008 12:38 AM Ahsan Riaz
No one answered AM Matt question

How in the heck does the sum() in snippet #2 output 1,2 ??
Can ANy one tell.
Saqib if you can please

# re: What is LINQ? 2/1/2008 10:05 AM Chad Hynes
I'm fairly certain that the sum() in snippet #2 should output one line, 14. It's likely just a mistake made by copy-paste from the original snippet.

# re: What is LINQ? 2/4/2008 8:03 PM Radheshyam Rathi
This is really nice article with good examples.

Thank you.

# re: What is LINQ? 2/6/2008 12:02 AM Asem
Great link.........

Thanks a lot....

Asem Ibohal

# re: What is LINQ? 3/5/2008 11:12 PM Trilok
superb intro to linq

# re: What is LINQ? 3/21/2008 6:50 AM amitabh
nice stuff to give a brief understanding of LINQ

# re: What is LINQ? 3/26/2008 8:44 AM Ihab
Very good. It gave me an overview on Linq. Thank You

# re: What is LINQ? 3/28/2008 10:42 PM Ahsan
Thanks a lot.very nice article on Linq.

# re: What is LINQ? 4/23/2008 7:24 PM Debasmit Samal
Thanks alot.

really it helped me a lot and lot

# re: What is LINQ? 4/27/2008 12:06 AM princy verma
its a gud article n helpd mee a lot
plz can u give an article on latest version of .net also?

# re: What is LINQ? 4/28/2008 7:10 PM Suby
Absolutely brilliant

# re: What is LINQ? 5/14/2008 3:47 PM Muthukumaran
Superp introduction

# re: What is LINQ? 5/18/2008 10:01 PM Jothibasu
It is really nice Article

# re: What is LINQ? 5/22/2008 9:00 PM Mahammed Ali
Introduction of LINQ is very nice.



# re: What is LINQ? 6/2/2008 11:25 PM Nushrat Ali
Hi Folks
this above example helps me a lot to understand about hte LINQ

i am heartly thank full to you

thanks a lot

Nushrat Ali
Sansoft IMS India

# re: What is LINQ? 6/9/2008 5:02 PM Icasper
great example, but the code snippets is a little strange from the basic sql syntax i know, whew!

# re: What is LINQ? 6/9/2008 8:13 PM GuillAbegoon
How soon this LINQ technology will boom. I like this technology I hope this could also be available in VS2005

# re: What is LINQ? 6/30/2008 8:00 PM Kishaloy
Really nice article dude. It helped me a lot to get a overview of LINQ.

# re: What is LINQ? 7/3/2008 9:01 PM Deepak & Sachin
Man Hi man me sayad har developers yeisha hi kuchha khoj
rahethe jo Micosoft New Baby Ko Birth Dekar Pura Kiya,
And
Thanks saquib Bhai For Brilliant Articles
////////////////////////////////////////////////////////////////////////
Deepak sah & Sachin Sah
Software Programmer
Salleri Technology Inc.
Aadarshnagar,2nd floor Runghta Market Birgunj,Nepal

Mobile : +977-9806882802
email : deepak_niitbrj@yahoo.com/deepak@usnet.com.np
web : www.salleri.com.np
web : www.niitbrj.com.np
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

# re: What is LINQ? 7/11/2008 10:55 PM RevathiPrasannaa
Very nice article
Thanks a lot

# re: What is LINQ? 8/4/2008 1:03 PM Nushrat Ali
Hey Jothibasu.
Zangatang?

# re: What is LINQ? 8/19/2008 12:15 AM Pushpa Latha
This link is very useful.
Its very simple to undestand.
Now, I have got the idea about the LINQ.

# re: What is LINQ? 8/19/2008 1:36 AM Kiran Kurapaty
Thanks for sharing the information. Its really very useful to understand the basics.

# re: What is LINQ? 9/4/2008 4:03 AM Kamlaesh
A good Article to start LINQ

Regards,
Kamalesh

# re: What is LINQ? 9/16/2008 3:20 AM Priyanka Chandok
Nice explanation.
Can u send me more details about LINQ.
That is, Its connectivity with ADO.net and XML with examples.
I wil be very thankful

# re: What is LINQ? 10/7/2008 1:48 AM Mehdi Danesh
Thank you for a very nice atricle regarding LINQ, it helped me to undrestand what LINQ is. The examples you provided demonstrates data populated within an array. Can you provide an example pulling data from SQLServer?
an example comparison between doing a traditional ADO VS LINQ?

Thanks again
M. Danesh

# re: What is LINQ? 10/13/2008 5:25 PM pramod
this gives me basic information of LINQ
but i wanna to
that how it will work with asp.net

# re: What is LINQ? 10/30/2008 5:56 PM cpastudent
Is the result of Snippet #2 14?

# re: What is LINQ? 11/3/2008 6:16 PM Madhu Agarwal
Its a nice article...LINQ seems to have great powers... we would like to know the internal processing of LINQ and perfomance effects..Thanks

# re: What is LINQ? 11/5/2008 6:45 PM Pramod Pandurang Gavate
Nice article to get in LINQ

# re: What is LINQ? 11/18/2008 4:51 PM rajeesh
very useful article.It gives good introduction to LINQ.

# re: What is LINQ? 11/21/2008 1:05 AM sarath
hi men hats off to you....
i got what i wanted from your article ...
thanks

# re: What is LINQ? 12/14/2008 7:22 PM vijay
Very Nice basic Article for new beginner.

# re: What is LINQ? 12/15/2008 8:09 PM jobin
good article...its help more

# re: What is LINQ? 12/15/2008 8:10 PM jobin
nice one

# re: What is LINQ? 12/28/2008 10:52 PM Shaheel
Cool explanation.
Can u send me more details about LINQ.
That is, Its connectivity with ADO.net and XML with examples.
I will be very thankful

# re: What is LINQ? 12/29/2008 5:04 PM skeptic
Why on earth would you load up all your objects into a List and THEN filter/sort them? Seems like LINQ is trying to do the database's job for it, which can only lead to poor performance and bad architecture (functionality in the UI instead of the back end).

# re: What is LINQ? 12/29/2008 11:20 PM Raju
Really Good man.....But you said "In my up coming post you will see both LINQ to SQL and LINQ to XML code snippets. "
we are waiting for you reply...

# re: What is LINQ? 1/20/2009 7:30 PM kalyan
Thanks you so much..
Now I have a clear idea on LINQ.

# re: What is LINQ? 2/10/2009 6:56 PM Muhammad Shoaib Siddiqui
Thanks so much...
Its really great article in LINQ. This article shows the power of LINQ.



# re: What is LINQ? 2/24/2009 6:00 PM Kiran
I Don't Know More Information Plz Send Me Email on my
Email ID.

# re: What is LINQ? 2/25/2009 6:05 PM suresh
Thanks alot for posting such a nice article about LINQ.
As of now i clearly understand what exactly LINQ and how to use it.Can u post some of examples which are related for realtime senarios.

thanks in advance


# re: What is LINQ? 2/27/2009 10:56 PM www.WatchTechVideos.com
Very Good Writeup about LINQ... Sample programs are simple but explains us more about LINQ...

You may be interested in this video which explains more about LINQ
http://wtv.watchtechvideos.com/topic180.html


Regards,
www.WatchTechVideos.com

# re: What is LINQ? 3/5/2009 1:44 AM Hajan Selmani
Great Article.
Very simple and good explained.
-----------------------------------------------
Hajan Selmani, BSc
Application Developer
EduSoft, IT Engineering
Stiv Naumov 1/1-1 , Skopje, R. Macedonia
tel. +389 2 3127323 ; +389 2 3128462
fax. +389 2 3215414
hajan@edusoft.com.mk
www.edusoft.com.mk

# re: What is LINQ? 3/7/2009 2:34 PM Armando J. Amor Jr.
I think link would be the easiest way for me to write more difficult code unlike the old way of programming language. Hope microsoft can more documentations about this. Thank you very much.

# re: What is LINQ? 3/20/2009 12:12 AM Bhup
Thanks alot......
i am an indian say thanks in hindi--"bahut badiya DADA"

# re: What is LINQ? 3/29/2009 3:18 AM Naveen Kumar Mishra
It is good affert

Nice

Good
thanks
Naveen Mishra
Syatem Analyst
Infoedge Solutions Pvt Ltd.
naveen@infoedgesolutions.com

# re: What is LINQ? 4/15/2009 6:28 PM Zulqarnain Satti
Good Article. You explain LINQ very well. Thanks alot and keep it up...TC

# re: What is LINQ? 5/4/2009 4:19 AM Narsimha



this is very good.

Thank you..

with Regards
Narsimha

# re: What is LINQ? 5/5/2009 5:56 AM sanjeeb
Hi

very nice topic.

# re: What is LINQ? 5/10/2009 10:36 PM Raj
What an article!!!! :) It rocks

# re: What is LINQ? 5/17/2009 7:38 PM nazi
it was very helpful to me.......... thank u a lot........

# re: What is LINQ? 5/25/2009 6:07 PM Arvind
really very good article.
thanks

# re: What is LINQ? 6/1/2009 12:34 AM jeneesh
Very nice article...

Thanks a lot....my dear friend.

# re: What is LINQ? 7/17/2009 1:35 AM Sami
Excellent !
I am newbie to LINQ and have path now.

# re: What is LINQ? 7/21/2009 6:49 AM vijay
Very nice one

# re: What is LINQ? 8/10/2009 12:57 AM Yasir Akram
Excellent !
Very good introduction to LINQ

# re: What is LINQ? 8/13/2009 2:05 AM Rajesh Kardile
Good
Best
Better

# re: What is LINQ? 8/19/2009 6:43 AM Unmesh Takalkar
Very Nice article

# re: What is LINQ? 8/29/2009 9:21 AM Rajneesh Hajela, Mumbai
LINQ defines a set of query operators that can be used to query, project
and filter data in arrays, enumerable classes, XML, relational database,
and third party data sources.

# re: What is LINQ? 8/30/2009 8:19 AM fakhrad
Very nice Article About Linq Tanx

# re: What is LINQ? iam madduri srinivas yadav 9/2/2009 3:40 AM madduri srinivas yadav
Thanks for giving some ideas about linqs


# re: What is LINQ? 9/23/2009 6:58 AM Lavanya
Nice article which gives a good starting knowledge for introduction into Microsoft LINQ.

I need more links on latest features on .Net Framework.


Thanks,
Lavanya

# re: What is LINQ? 9/29/2009 10:58 AM PinkFloyd43
linq, wtf, when would I want to do this crap!

# re: What is LINQ? 10/23/2009 11:53 AM Preethi
Very good article...Good work

# re: What is LINQ? 11/21/2009 5:39 AM Business Plan Writing
Hi,
Interesting way to look at; for the most part, I agree with you. It would be great if got more post like this. I appreciate it.


# re: What is LINQ? 11/25/2009 1:46 AM avdesh
nice article

# re: What is LINQ? 11/25/2009 1:46 AM avdesh
nice article

# re: What is LINQ? 12/2/2009 2:58 AM prathsh
Hi, this is a very good article for the beginners of LINQ as well as the good for the knowledge points also.

Prathesh

# re: What is LINQ? 12/3/2009 6:15 AM Kirit Patel
very good article

# re: What is LINQ? 12/10/2009 1:06 AM Rishad
Its really very nice article

# re: What is LINQ? 12/22/2009 8:29 AM Miten Shah
very nice article

# re: What is LINQ? 1/7/2010 1:34 AM praka
How in the heck does the sum() in snippet #2 output 1,2 ??Please Change output to 14

# re: What is LINQ? 1/13/2010 5:57 AM Santosh
Nice presentation to get a basic idea about LINQ.

# re: What is LINQ? 1/20/2010 12:18 AM Ramin Habibi
Hi
Thanks my friend,it's nice

# re: What is LINQ? 2/1/2010 1:37 AM roger
hai excelent explanation,its very helpful to me thanks

# re: What is LINQ? 2/15/2010 8:50 AM reeee
vry bore

# re: What is LINQ? 3/12/2010 6:51 AM Rahul
Very simple to understand. I was searching to get the idea about LINQ and finally this sit help to find what it is. Thanks a lot..

# re: What is LINQ? 4/6/2010 1:53 AM aida
hi thank you.but i dont know how update or insert or delete data from database with linq.can you help me? thank you

# re: What is LINQ? 5/4/2010 6:13 AM kuchgane
nice article..check this out:
http://mindpower-kuchgane.blogspot.com/2010/05/mindpower-fact-hunt-linq-net-feature.html

# re: What is LINQ? 5/5/2010 10:19 AM raj
Very good article
that help to reduce the time in development

# re: What is LINQ? 5/21/2010 7:03 AM Dinesh Sharma
Really Very Nice Article for Beginner...........

Dinesh Sharma
MatrixSolution
Thank u

# re: What is LINQ? 6/22/2010 2:12 AM Elanchezian
Very Nice Article for linq Beginners

# re: What is LINQ? 6/29/2010 8:49 PM karthikeyan
nice explanation :-)

# re: What is LINQ? 7/14/2010 4:27 AM GaneshPpawar
nice article.

# What is LINQ? 8/4/2010 4:06 AM Brajesh Kumar
It's really nice for begineers..

# re: What is LINQ? 8/20/2010 10:27 AM vijayeta
GUD MATTER

# re: What is LINQ? 9/1/2010 12:35 PM saikanth
perfectly defined What is LINQ?
nice article.....
tx for posting

# re: What is LINQ? 9/8/2010 3:44 AM nikeeta
good article waiting for linq to sql

# re: What is LINQ? 10/15/2010 4:48 AM Sharmistha
Learning made simple :)

# re: What is LINQ? 11/26/2010 3:16 AM debi patnaik
an informative article on LINQ

# re: What is LINQ? 12/5/2010 12:24 AM karthik
Nice Article from linq

# re: What is LINQ? 12/9/2010 1:37 AM Ravi Nigam
good one

# re: What is LINQ? 12/10/2010 6:02 AM Mohammed.Khaleeluddin
good article on linq to objects but linq to sql is most desirable pls post asap thanx.

# re: What is LINQ? 12/13/2010 1:09 AM shrikant
nice article for novice thanks .....

# re: What is LINQ? 12/24/2010 1:26 AM jaaydaad.com
It's really nice for begineers

# re: What is LINQ? 1/6/2011 4:35 AM Shahnawaz
Really nice work.

Appreciated your article.

Very Helpful

# re: What is LINQ? 2/7/2011 2:01 AM Junaid
Wonderfull starter for LINQ
Thanks a lot dude.. :)

# re: What is LINQ? 2/23/2011 6:06 AM srinivas
Really it,s amazing for beginners.please mail new concepts about LINQ.Thanks for ur Tutorial

# re: What is LINQ? 3/7/2011 6:19 AM LINQ Hosting
Very nice topic about LINQ!
Thanks very much.
I like the article.

# re: What is LINQ? 4/1/2011 3:19 AM chandan barnwal
Hi this is a very good Articl for the beginnes of Linq.as will as the good for the knowlege points also chandan

# Good tutorial 4/8/2011 2:28 PM Student discounts
Thank you for letting me understand what LINQ is. It is quite technical and some terminologies are still jargon to me. This is a good start though.

# re: What is LINQ? 4/24/2011 11:33 PM Pavan kumar konduri
Very Nice Introduction about LINQ,Thank for posting this introduction

# re: What is LINQ? 4/27/2011 11:01 PM rakesh
It's really nice for list concept.

# re: What is LINQ? 5/19/2011 9:50 PM r singh
Very Nice Introduction about LINQ,Thank for posting this introduction

# C: What is LINQ? 5/19/2011 9:54 PM V
Microsoft Babies
Microsoft new baby yes I am talking about LINQ stand for Language-Integrated Query is now available as a integral part of Visual Studio Orcas. Microsoft releases the new Visual Studio with the name of Orcas and all Microsoft previous efforts (Windows Communication Foundation WCF, Windows Workflow Foundation WWF, Windows Presentation Foundation WPF, Windows CardSpace and LINQ) are integrated in this Studio. From last one and half years Anders Hejlsberg team done a tremendous job in the overcoming the gap between the data impedance. Mr. Anders team gives a native syntax to developers in the form LINQ to C# and VB.Net for accessing data from any repository. The repository could be in memory object, database (still MS SQL Server only) and XML files.

What is LINQ?
Still lots of folks don’t understand what LINQ is doing. Basically LINQ address the current database development model in the context of Object Oriented Programming Model. If some one wants to develop database application on .Net platform the very simple approach he uses ADO.Net. ADO.Net is serving as middle ware in application and provides complete object oriented wrapper around the database SQL. Developing application in C# and VB.Net so 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. If here I can say SQL statements are become part of the C# and VB.Net code so it’s not mistaken in form of LINQ. According to Anders Hejlsberg the chief architect of C#.

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

LINQ has a great power of querying on any source of data, 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. 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}


I hope few above lines increase your concrete knowledge about Microsoft LINQ and now we write some code snippet of LINQ.

1. Code Snippet

# re: What is LINQ? 5/19/2011 9:56 PM What is LINQ?
using System;

public class Patient
{
// Fields
private string _name;
private int _age;
private string _gender;
private string _area;
// Properties
public string PatientName
{
get { return _name; }
set { _name = value; }
}

public string Area
{
get { return _area; }
set { _area = value; }
}
public String Gender
{
get { return _gender; }
set { _gender = value; }
}
public int Age
{
get { return _age; }
set { _age = value; }
}
}

Here is my code that intiliaze patients object with following data.


List<Patient> patients = new List<Patient> {
new Patient { PatientName="Ali Khan", Age=20, Gender="Male" , Area = "Gulshan"},
new Patient { PatientName="Ahmed Siddiqui", Age=25 ,Gender="Male", Area = "NorthKarachi" },
new Patient { PatientName="Nida Ali", Age=20, Gender="Female", Area = "NorthNazimabad"},
new Patient { PatientName="Sana Khan", Age=18, Gender="Female", Area = "NorthNazimabad"},
new Patient { PatientName="Shahbaz Khan", Age=19, Gender="Male", Area = "Gulshan"},
new Patient { PatientName="Noman Altaf", Age=19, Gender="Male", Area = "Gulshan"},
new Patient { PatientName="Uzma Shah", Age=23, Gender="Female", Area = "NorthKarachi"}};

Patient p = new Patient();
p.Age =33; p.Gender = "male";
p.PatientName = "Hammad Ali";
p.Area = "Defence";
patients.Add(p);

I have been written a blog on the new way of initilaztion.

This code snippet fetch those records whose gender is equal to “Male”.

gdView.DataSource = from pa in patients
where pa.Gender == "Male"
orderby pa.PatientName, pa.Gender, pa.Age
select pa;
gdView.DataBind();

The following code snippet uses the selection operator type, which brings all those records whose age is more than 20 years.

var mypatient = from pa in patients
where pa.Age > 20
orderby pa.PatientName, pa.Gender, pa.Age
select pa;

foreach(var pp in mypatient)
{
Debug.WriteLine(pp.PatientName + " "+ pp.Age + " " + pp.Gender);
}
The following code snippet uses the grouping operator type that group patient data on the bases area.

var op = from pa in patients
group pa by pa.Area into g
select new {area = g.Key, count = g.Count(), allpatient = g};

foreach(var g in op)
{
Debug.WriteLine(g.count+ "," + g.area);
foreach(var l in g.allpatient)
{
Debug.WriteLine("\t"+l.PatientName);
}
}
This code snippet determine the count of those records, which lay in above 20 years.

int patientCount = (from pa in patients
where pa.Age > 20
orderby pa.PatientName, pa.Gender, pa.Age
select pa).Count();

# re: What is LINQ? 5/25/2011 9:11 PM Tanushree Gaonkar
Nice link

# Business Plan writers 5/30/2011 7:43 PM Business Plan
If you are looking for professional business plan consultants, business plan experts and business plan writers, please feel free to contact B-Plan Experts business plan consultant - your best business plan expert.

# re: What is LINQ? 6/6/2011 6:20 AM narendra Sonone
with above example of patient it is easy to understand. Thanks.

# # Business Plan writers 7/7/2011 12.46 PM 6/6/2011 7:17 PM Business Plan Consultant
If you are looking for professional business plan consultants, business plan experts and business plan writers, please feel free to contact B-Plan Experts business plan consultant - your best business plan expert.



# re: What is LINQ? 7/4/2011 3:29 AM mrityunjay mall
it is very easy to understand. i like the article thanks


# re: What is LINQ? 7/12/2011 6:38 AM Sandeep Kheriwal
thanks....this is a good artical

# re: What is LINQ? 7/13/2011 6:44 AM punya
very nice and very helpfull article
thankyou

# re: What is LINQ? 7/18/2011 12:48 AM Imdadhusen
Thanks for sharing excellent tutorial on LINQ.

# re: What is LINQ? 7/21/2011 6:45 PM Rahul Rajput
Greate It's Really good For Beginners..
Waiting For Linq To XML Article

# re: What is LINQ? 7/21/2011 6:53 PM SharePoint Consulting
There are certainly a lot more details to take into consideration, but thanks for sharing this post.
SharePoint looks much more professional. It comes at a cost, but offers a number of services designed for larger companies.
SharePoint Consulting

# re: What is LINQ? 7/24/2011 10:40 PM Sachin Ambekar
Why few people are worried about wrong out put for Sum() snippet #2. Please focus on the technology buddy!!

# re: What is LINQ? 7/31/2011 4:08 PM Sundar
Nice Article on LINQ.

# re: What is LINQ? 7/31/2011 4:08 PM Sundar
I really dont know before what is LINQ,but now i have a clearcut idea on it.

# re: What is LINQ? 8/8/2011 12:21 AM mritunjai
thankxxx a lot.

# re: What is LINQ? 8/19/2011 6:02 PM shilpa
It's very good ,those who dnt know about the LINQ they can easily understand.
Thanks.......

# re: What is LINQ? 9/9/2011 9:06 AM Holiday Forum
Great post! I?m just starting out in community management/marketing media and trying to learn how to do it well. Singapore travel

# re: What is LINQ? 9/9/2011 9:11 AM Agen Bola
like this idea, thanks for sharing. 388A Sbobet Casino

# re: What is LINQ? 9/14/2011 3:33 PM sheeloo sachan
Its a very nice article

# re: What is LINQ? 9/28/2011 5:37 PM jaya
nice article with linq..

# re: What is LINQ? 9/29/2011 5:16 PM Soumya
Hi,
The output for the Example2 code snippet is shown as "1", "2"

Actual output is "14".which is the sum of 2, 4, 6, 2.

Could you please Chech that Out


# re: What is LINQ? 10/5/2011 9:35 PM anand pal
how can i add new object to the list??

# re: What is LINQ? 10/21/2011 5:16 PM Anuj Agnihotri
This is very interesting topic and I think it is clear Linq for every new programmer.

#  What is LINQ? 10/21/2011 5:18 PM Anuj Agnihotri
This is very interesting topic and I think it is clear Linq for every new programmer and I want to know about Generics Plz clear generics in Simple way

# re: What is LINQ? 10/22/2011 7:18 PM reza
very gooooooooooooood.im from iran-abadan

# re: What is LINQ? 11/16/2011 10:24 PM Ajay Singh
Very nice article. I really enjoyed it reading. And it also cleared lot of my doubts about LINQ in .Net. Check this link...
http://www.mindstick.com/Blog/53/LINQ%20in%20NET
Its helped me to complete my task.

Thanks Everyone!!

# re: What is LINQ? 11/19/2011 3:46 AM Meena
Very nice...very useful too

# re: What is LINQ? 11/30/2011 11:13 PM grajkumarmsc
Very nice Article,
I want to know about Generics Plz clear generics in Simple way with best example.
Thanks



# re: What is LINQ? 12/2/2011 3:46 PM Tapan
it's helpful.

Reallly Nice Article.
Hope for Some Others
Thanks.


# re: What is LINQ? 12/2/2011 3:48 PM Tapan
it's very helpful.

and very simple.
if i found more query in future the i will ask u?
thanks.

# re: What is LINQ? 12/11/2011 5:07 AM siva
Nice super good

# re: What is LINQ? 12/12/2011 6:51 PM suman
it's very helpful.and very simple.
but how to connect database please send steps for me



# re: What is LINQ? 12/18/2011 6:23 PM One Shoulder Evening Dresses
Picking to buy bridesmaid wedding dresses in colors like red and green in December, pale yellow and lavender in spring will be a good deal much less high-priced. Also choosing colours that are readily available can cost less than obtaining custom fabric with alternative of certain colours.





# re: What is LINQ? 12/29/2011 5:01 PM Sadia Tariq
It's really a nice topic and the examples mentioned made my concept clear about how to use LINQ.

Thanks.

# re: What is LINQ? 1/8/2012 9:41 PM Madhu Jajula
Gud one...

# re: What is LINQ? 2/8/2012 11:38 PM Pawankumar
Very Well. . .

Pawan Dubey
LNT Infotech


Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: