Posted By: scobleizer | Sep 13th, 2005 @ 11:27 AM | 339,801 Views | 90 Comments
LINQ stands for Language INtegrated Query and in a nutshell, it makes query and set operations, like SQL statements first class citizens in .NET languages like C# and VB.

Here we visit Anders Hejlsberg in his office to get more on LINQ. Dan Fernandez, also seen in this video, just put up a blog post about LINQ.
Media Downloads:
Rating:
2
0
Cairo
Cairo
I want my waffle sundae, give me my carbs!
daniel wrote:

I find it slightly disturbing how this is presented and everyones comments here. There are interesting comparaisons to be made. There is a technological context.


It's ALL NEW! OMG! CHANGES EVERYTHING!

</not>


gswitz
gswitz
Geoff
Sensational! Wow! Give that man an XBox!

http://msdn.microsoft.com/netframework/future/linq/default.aspx

For those who didn't make it to the end, here's the link for the bits.
Dan
Dan

I just wanted to quickly respond to some of the questions

Will LINQ support querying something besides IEnumerable in the future? How would I tell LINQ to query a Binary Space Partition? (requiring LINQ to know about the data container)

You can implement the LINQ pattern (your custom implementation of the LINQ standard query operators like from, where, select, etc) for your own data domain.

Also, in the NorthWind example is LINQ doing a full table scan every time? Or does it take advantage of existing indexes? But you're not duplicating the SQL Server engine inside the CLR ... are you?

When querying against Northwind, you are using DLinq,  which is an implementation of the LINQ pattern for databases. What DLinq does is translate a LINQ query into a SQL statement, send it to the database and convert the results back into strongly typed objects for you.  It uses deferred execution which basically means you don't have to pay a price until the last possible time form an execution standpointl. We'll be posting more information on how execution works soon.

This is not quite 'VERY VERY VERY' different. It's using lambda functions like Anders does in the same context for the same purpose. No need to define classes. Don't get me wrong what Anders is doing is great. It has graceful syntax too. It's just a great evolution not an earth shattering revolution.

In my opinion, the biggest change is that we're abstracting out the data store, meaning you can program against objects, relational data, and XML using a single, unified programming model. For example, you could use the VSTO (Visual Studio Tools for Office) API's and write a LINQ sample to query your email, like find all emails where:
1) the subject contains "LINQ"
2) sent in the last month
3) that were marked "urgent".

The Ruby libraries on the other hand are specifically for relational data. As an astute C9'er pointed out earlier, you can even imagine implementations of the LINQ pattern for Active Directory or WinFS where you can reuse the same syntax (from, where, select) without having to understand each domain. With the LINQ Project, you have one programming model across all domains. IMO, that's huge Smiley

I hope the VB team implements this stuff into VB.NET. This is just an awesome feature set!
LINQ will absolutely be in both VB and C#.  In fact, you can download the VB Tech Preview compiler at: http://download.microsoft.com/download/2/a/4/2a405b66-1b1c-4fca-bfbf-007aad63d307/LINQ%20VB%20Preview.msi

Thanks everyone for the great feedback so far!
-Dan

very cool - I love seeing how everything, both technology (.NET framwork, generics, SQL Server, WPF, etc) and ideas (power of a virtual machine + garbage collection; having a DML as a 1st class citizen in your language like xBase; having a standard way of querying across different data sources like odbc was designed to do; "ORMesque-ness", vector graphics, ...) is just coming together/evolving/building on top of each other to build something out of this world - way to go guys! 

In any one particular space, Microsoft has some really good competitors (eg. Flash is great for vector graphics today, PDF is the ubiquitious standard for transferring documents, java is a productive language for writing server side code), but its the sum of your parts (especially when you bring them together) that puts the MS platform well out in front (in my mind at least).

I should probably just read the documentation, but will LINQ be able to join data from 2 seperate data sources - eg. SELECT a.customer, b.product_photo FROM <sql data source> a JOIN <xml data source> b? ON (a.productid = b.productid)?

Thanks for the video...it was very interesting and I wish you guys would put up more videos from Anders.  I am somewhere in the middle on the LINQ phenomenon, however, and again I keep going back to my old comment:

Why now?  Why not a few years ago?  Were there performance issues?  The underlying technology has certainly been there for a while.  Or was it an internal structuring/organizational issue? I can see reasons for both.  Conceptually, however, only some of this is "radical".

Dan wrote:
In my opinion, the biggest change is that we're abstracting out the data store, meaning you can program against objects, relational data, and XML using a single, unified programming model. For example, you could use the VSTO (Visual Studio Tools for Office) API's and write a LINQ sample to query your email, like find all emails where:
1) the subject contains "LINQ"
2) sent in the last month
3) that were marked "urgent".

Yes, this is big leap forward, and I'm all for it.  I started using a bit of C# last month, and I am toying with the idea of building a language parser with it. However, relational databases have their limits, too, although the model has generally carried the industry a long, long ways.

Dan
Dan
...will LINQ be able to join data from 2 seperate data sources - eg. SELECT a.customer, b.product_photo FROM <sql data source> a JOIN <xml data source> b? ON (a.productid = b.productid)?

Yes, it will, in fact in the Jim Allchin keynote, Anders and Don wrote a LINQ query that joins the results of Process.GetProcess() to a database table and then displayed the results as XML.

Thanks,
-Dan

This is great, I can't wait to use it. I noticed that the VB.NET syntax is more similar to a standard SQL SELECT statement. I understand the reason why in C# is arranged differently, but I really wish they would go the extra mile and tweak the C# compiler.

Karim
Karim
Trapped in a world he never made!
Cool!  So what I'm seeing is, C# finally has a Variant data type?  Nice to see they're catching up to VB 6.0.  LOL

Just kidding.  I did hear the words "strongly typed" used repeatedly.

But it's interesting to see the productivity people had with the older VB (where you did not have to worry about data types) combined with the robustness of C# (where you do have to worry about data types) -- but now it's the compiler that does the worrying for you.

That in itself is going to be a huge win.  All those null vs. dbnull vs. empty string bugs... GONE.

The fact that it's universal... wow.  Now maybe when I code against Outlook I can stop messing with collections and enumerators and retrieve the items I want in 5 lines of code instead of 50... using the same syntax I use to query databases...
How does one construct a dynamic where clause in LINQ?
... Select clause?

For instance, If we intend to build a screen that allows the user search and display customers using customers' Name, Phone #, City,  and etc...

Today, a constructed SQL will look apporx like this:

string sqlStmt = "SELECT * FROM CUSTOMER WHERE ";

if(txtCity.Text.length() > 0)
    sqlStmt += " CITY = '" + txtCity.Text + "' "; // London ; )

...

What will be an equivalent in LINQ to accomplish the above shown sql?
Microsoft Communities