A LINQ Thought


LINQ stands for Language Integrated Query. I want to stress on “Integrated” because I think the strength of LINQ comes from the fact that it is a data query engine that is integrated with .Net languages. This very reason gives us many features that we as developers are comfortable
using in a language into our data manipulation operations.

Lets take a simple example,

var query
= from customer in CustomerTable.AsEnumerable()
where customer.Field("Name").ToLower().Contains("John")
select customer;

In the above example, we are using simple string functions that are part of C# string class to do our comparisons for our data fetch.
Lets take another example, where we will use a C# function to evaluate a sub-query/expression,

var query
= from customer in CustomerTable.AsEnumerable()
where
customer.Field("Name").ToLower().Contains("John")
select new Customer 
{
Name = customer.Field("Name"),
State = customer.Field("State"),
CustomerType = GetCustomerType(customer.Field("State"))
};

In the above example, GetCustomerType() function is used inline with a LINQ query to evaluate some business rule.
In short, with great flexibility like this, LINQ has made life of developers much easier!

Cheers!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s