Dr. Neil Roodyn - Fooling around in Scoble's office

Wow
Does ths not look like FoxPro? Where you can intermingle SQL with structure code in your source file? And get SQL extracts right into local vars?
Is it just me or are we back some 15 years' time?
bobEnglish wrote:Wow
Does ths not look like FoxPro? Where you can intermingle SQL with structure code in your source file? And get SQL extracts right into local vars?
Is it just me or are we back some 15 years' time?
Steve “Lightning” Trefethen posted a link to Anders Hejlsberg's LINQ video on Channel 9 Forums, so I was intrigued and took a look. After all, Anders was the father of Delphi.
In the video, at about 7 mins 50 seconds into it, Anders was talking about Language INtegrated Query, and he was explaining to the audience where “Where” and “Select” came from, “because an array doesn't have a select or a where guy” and that C# 3.0 implements a new thingy known as extension methods, which is the “ability to extend an existing type with new methods”.
Sounds like he's talking about Delphi's class helpers concept. You can take the man out of Borland, but you can't take Borland out of him... ;o)
Class helpers or extension methods have been available in the Delphi language since Delphi 8 came onto the scene nearly 2 years ago.
And the "var" thingy? Is he sneaking parts of the Delphi language into C# 3.0? ;o)
Wonder how long it will be before we get this in a product.
Will this be the death of DataSets? DataSet has not been able to fit into the web service world anyway (no type information in wsdl).
Oh.
My.
God.
This is one of those "change everything" things.
By itself, this is impressive, but combine this with WinFS and Web service classes... yeeow, the possibilities are staggering! No wonder they're so excited about this.
One quibble - when Anders was talking about the reason why the "from" clause had to be first, it made a lot of sense, but then I went to the VB 9.0 whitepaper and saw this:
Dim SmallCountries = Select Country _
From Country In Countries _
Where Country.Population < 1000000
For Each Country As Country In SmallCountries
Console.WriteLine(Country.Name)
Next
The VB.NET syntax for LINQ looks more like SQL than the C# syntax. However, Anders' point about the C# syntax being better for XML querying still holds and is demonstrated by this VB.NET 9 snippet later in the whitepaper:
Dim CountriesWithCapital As XElement = _
<Countries>
<%= Select <Country Name=(Country.Name)
Density=(Country.Population/Country.Area)>
<Capital>
<Name><%= City.Name %></Name>
<Longitude><%= City.Longitude %></Longtitude>
<Latitude><%= City.Latitude %></Latitude>
</Capital>
</Country> _
From Country In Countries, City In Capitals _
Where Country.Name = City.Country %>
</Countries>
There's a lot of XML cruft before you get to the "from" and "where" of your LINQ code. It's easy to imagine how nasty it could get with a more complicated XML document. The C# syntax clumps all the LINQ syntax at the beginning and leaves the XML cruft for
the end.
By the way, note the ASP.NET-like syntax in VB.NET 9!
Minh wrote: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?
daniel wrote:Could someone say ORM at least once.
daniel wrote:Yes there are some neat things here but a lot of it resembles very closely what I use Ruby for everyday + some type checking.
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.
Minh wrote: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?
I think, the answer is how do they implement the IEnumerable<T> interface. It's possible to open the SQL query within the GetEnumerator() implementation, then it can build the correct and exact sql query which returns the requested result only from the server.
So, if you don't enumerate on a LINQ construct whatever is that, you don't contact with the sql server. A rude sample:
class SampleClass : IEnumerable<string>
{
IEnumerator<string> IEnumerable<string>.GetEnumerator()
{
using(SqlConnection connection = new SqlConnection(ActiveScribaDatabase.ConnectionString))
{
using(SqlCommand command = new SqlCommand("select CustomerName from Customers where zip=345", connection))
{
connection.Open();
using(SqlDataReader datareader = command.ExecuteReader())
{
while(datareader.Read())
{
yield return datareader.GetString(0);
}
}
}
}
}
}
davida242 wrote:
Don't worry. When you query a database via LINQ, the query expression that you construct in C# is translated into the corresponding SQL query and executed against the database.
my jaw is on the floor!
daniel wrote: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.
Question. What about locking? How does locking syntax work when selecting over a collection? Is it just:
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
lock(syncRoot)
{
var lowNums =
from n in numbers
where n < 5
select n;
}
Console.WriteLine("Numbers < 5:");
foreach (var x in lowNums) {
Console.WriteLine(x);
}
TIA
Comment removed at user's request.
Ooooooooo ..... uuuuuuuggggg ...... eeeeeeerrrrrrrr ..... eeeeeeeeek!
I've had a cow!
How good is this! I want a T-Shirt with the words LINQ on it!
davida242 wrote:
I was only thinking about the typical ORM available for .Net.
Is at least the fact that all of this is done with strong typing something new?
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.
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
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:
https://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
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.
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.
Azura wrote:How does one construct a dynamic where clause in LINQ?
... Select clause?
Azura wrote: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?
DashNY,
I thought for some time how to reply to you… you criticize but do not provide a relevant solution.
You focus on details in VB, which is like focusing on trees while we are talking about the forest. In any case VB is not used for large enterprise level applications.
It is arrogant to assume that others understand less or are less intelligent then you.
Lastly, please focus on the discussion at hand and make relevant posts, keeping your advices to yourself, unless asked for.
XiXora wrote:HE GREW A BEARD?!
anyway back to w\tching video, i hope this give me a clue wtf happened to object spaces
I love the poster behind Anders:
B#
C#
J#
I#
Stay #
He is the best.. Awesome video, I can't wait to throw out my O/R mapper of choice.. I would be curious how the developers of NHibernate feel now.. NH 1.0 has just been released but has no support of C# 2.0, such as generics and man, I've grown grey hair
using NH.. LINQ is the way to go.
Gabor
I want an Anders Hejlsberg autograph. The guy was my hero for C#, my hero for C# 2.0 and now my hero for C# 3.0.
daniel wrote:Could someone say ORM at least once. These ideas weren't generated out of the blue. Yes there are some neat things here but a lot of it resembles very closely what I use Ruby for everyday + some type checking.
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.
Shark_M wrote:what is this guy saying?
I am new here, and begginner in C#,
To me its like chinese,
WHat the heck is IEnumerable of T for some T mean?
Can you put it in simple english for me?
"So can an somehow assign a name to my anonymous type to use elsewhere in my application?"
There is no way currently for an anonymous type to leak outside of the method it's used in. If you're going to do that, you should just create a type normally and give it a real name.
DashNY wrote:
Azura wrote: 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?
Concatenating SQL queries is evil. Search Google and MSDN for "SQL Injection Attacks" to see how dangerous it is.
Besides manually generating WHERE clauses is wrong from the proper design prespective.
I have a couple of questions.
In the overview document I could not find any references to how to define a primary key for a given relation when querying over a list of objects stored in, say, ArrayList? Or does the query perform a linear search?
Are there plans to support implicit parallelism for executing queries?
With strongly typed databases there has always been a challenge responding to the changes to the data schema. How do the new language extensions address changes to existing object schema? For example, if the layout of a class that is being queried has been changed, what is going to happen? Am I going to get a compile exception or a runtime exception when attempting to execute a query?
Typically, when quering over millions of records it would not be desirable to load the entire contents into memory. The question is if it is a requirement for the entire searchable contents to be loaded into memory before querying the data?
What types of joins the new extension is going to support?
How does the extension support the variable binding?
Appreciate your response
Thanks!
Was there a bit of product placement in this video? I was expecting hear the Coca Cola slogan at the end of this video.
LINQ looks interesting I liked reading this article
https://msdn.microsoft.com/netframework/default.aspx?pull=/library/en-us/dndotnet/html/linqcomparisons.asp
And when I get over the FROM SELECT thing I might give LINQ a try
daniel wrote:Could someone say ORM at least once. These ideas weren't generated out of the blue.
AggregateTestCollection aggTestColl = new AggregateTestCollection();
aggTestColl.Query.es.CountAll = true;
aggTestColl.Query
.Select (aggTestColl.Query.IsActive,
aggTestColl.Query.DepartmentID)
.Where (aggTestColl.Query.IsActive.Equal(true))
.GroupBy(aggTestColl.Query.IsActive,
aggTestColl.Query.DepartmentID)
.OrderBy(aggTestColl.Query.DepartmentID.Ascending,
aggTestColl.Query.IsActive.Ascending);
aggTestColl.Query.es.WithRollup = true;
aggTestColl.Query.Load();
MyGeneration wrote:
LINQ is cool, but sometimes I think folks at Microsoft think it's only real or invented if they do it ....
Rocky Moore wrote:I was sitting through the video thinking to myself that "this is cool", "that is cool", "Wonder where this will fit in my n-tier apps"..
Tensor wrote:
SQL Server has been developed over a long time and is very very good at doing things like getting the two records out of 100 million that you want very quickly. I hope DLinq takes advantage of this - I mean, does it as Minh asks do a full scan of the table or does it parse your DLinq query in to T-SQL?
Scottt40 wrote:Great video and information about Linq. Does anyone know if we will be able to use this type of language in Web Service calls. Would be great improvement. Will there ever be a wizard for creating web service calls?
Maybe VS will get there in Do you remember subclassing
get the object
name it
drop it into a new or existing class
Job Done
Try the on Pocket PC!!!!!!!
You cant even change the disabled forecolor so that you can see a disabled textbox!!!!
Richard JJS
qrt wrote:LINQ obviously abstracts the act of retrieving data away and allows for a declarativ programming style.
But almost any application also needs to update existing and insert new persisted data in databases.
It would be nice to see more demonstrations of Table join examples.
I've written several opject dumping utils over the years, is there anyway we could get a copy of yours it looks like a keeper