DateJS, OpenSource JavaScript Date Library Two interesting posts!
Dec 03

This is a series of posts regarding the new language improvements in VB 9. Bill Horst has written the second on which I came across here. As we all know VB LINQ statements enable SQL-like syntax for queries in the VB language. LINQ syntax doesn’t match SQL syntax exactly, so if you are already working with SQL or familiar with SQL queries, you may find yourself wanting to convert an existing SQL query to LINQ.

And here is an example with FROM clause:

A SQL SELECT statement always begins with a SELECT Clause, followed by a FROM Clause. A VB query expression always begins with a From Clause or Aggregate Clause (Aggregate will be discussed later). A basic SQL FROM clause specifies a table over which to query, and similarly, a LINQ From Clause specifies an object over which to query (CustomerTable). This object could represent “In-Memory” data, a SQL data table, or XML information. My examples use the “In-Memory” case, since it allows the simplest code. In addition to this data object, the VB From clause always includes an identifier for the current “row” (Contact), which basically functions as an alias.

SQL

SELECT Contact.CustomerID, Contact.Phone
FROM CustomerTable Contact

LINQ

From Contact In CustomerTable
Select Contact.CustomerID, Contact.Phone

Here is the whole post by Bill Horst.

One Response to “Converting SQL to LINQ”

  1. Converting SQL to LINQ - DISTINCT, WHERE, ORDER BY and Operators | Ajaxus place on the net Says:

    […] Horst continues with those simple examples. After this one here comes the other set. They are perfect to show basic syntax. Here are few […]

Leave a Reply