Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
provide the simple answer that i can easily understand?
Posted

LINQ
It stands for Language Integrated Query. We are using LINQ to Objects and the Objects part is any IEnumerable collection.  It enables you to query and manipulate data independently of data soureces. It's like a query language which can query any data source and any transform. It also provides full type safety and compile time checking. 

Why:
LINQ is intended to make it easy to query data sources. 
.NET Framework includes libraries that allow anyone to create a LINQ provider that can query any data source. 
LINQ providers that make it easy to query specialized data sources.
 
Share this answer
 
Comments
Member 10385151 15-May-14 1:17am    
can i use insert or update in linq? plz give me example...
[no name] 15-May-14 1:24am    
You perform Insert, Update, and Delete operations in LINQ to SQL by adding, changing, and removing objects in your object model. By default, LINQ to SQL translates your actions to SQL and submits the changes to the database.
see the following link
http://weblogs.asp.net/dotnetstories/archive/2010/12/17/select-insert-update-and-delete-data-with-linq-to-sql-in-an-asp-net-application.aspx
Linq is a generic 'front end' allowing you to query data in a similar way to using SQL on a database.

Whan I say 'generic' this just means there are different linq 'engines' that allow it to run over different things.

For example, there is Linq to SQL which allows you to write in your C# program, code which the Linq engine will translate (behind the scenes) into SQL, run, and return the results.

Best of all (IMHO) is Linq to Objects - that is, just using Linq natively in the language.

Say you have a collection of Animal objects in your program, and the user has selected they only want to see animals with 4 legs.

You could go

C#
foreach (Animal animal in Animals)
{
    if (animal.Legs == 4)
    {
        foundAnimals.Add(animal);
    }
}
return foundAnimals;


Which is fine, and works efficiently, but, well, takes a few lines of code.

With Linq you can do the same thing as

C#
return Animals.Where(a => a.Legs == 4).ToList();


There's loads more to it - but that's that's the basics (which is what you asked for!)
 
Share this answer
 
Comments
Member 10385151 15-May-14 1:05am    
But why i am used linq what are the benefits of using linq??
_Maxxx_ 15-May-14 1:59am    
The only real benefit is less code to be written. Instead of having to write lots of loops to search for or sort data, Linq does it for you.
Some people think its the bees knees, and try to use it for all sorts of things it's not really good for, and create messy Linq queries that are harder to maintain because of their complexity.

A good example where Linq is useful (IMHO) is in filtering collections (as I mentioned in my answer) - imagine the user can also select the colour, age, whether it has tails etc. etc. A single Linq query can provide the objects required from the collection, and sort them appropriately, without a) a long trip to the database or b) writing a 'foreach' or similar loop.,

Beyond that, it's really personal preference.

In fact in many circumstances Linq can be slower than writing a simple loop yourself, so where performance is a consideration it may not be the best tool.
Member 10385151 15-May-14 23:12pm    
Thank you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900