Archive for the 'linq' Category

Writing Queries with LINQPad

Friday, August 24th, 2007

I just discovered LINQPad. You can install .NET 3.5 Beta 2 and start writing LINQ queries against your databases. It does not require the LINQ CTP for Visual Studio 2005 or Visual Studio 2008. It is still a beta but I can see that it will become an invaluable tool once .NET 3.5 is released even though I will have Visual Studio 2008.

LINQ Performance versus ADO.NET

Sunday, August 19th, 2007


Last week I presented Deeper in LINQ for the Wisconsin .NET User Group and concluded with a speed test. The speed test compared ADO.NET to LINQ. The ADO.NET method called a stored procedure while the LINQ method generated the query inline. The results showed that LINQ is not as fast. The overhead is due to the LINQ for SQL provider that has to parse the query within the CLR and then generate the SQL that it sends over to SQL Server. The generated SQL is identical to what is in the stored procedure used by the ADO.NET method. The difference in timing is purely from preparing the query. And since LINQ to SQL uses ADO.NET once it generates the SQL it cannot possibly run faster than a direct ADO.NET implementation. The speed test was simply to show the difference.

[ Download the sample project: DeeperInLINQ.zip ]

In the attached screenshot you can see three tests. I wanted to make a LINQ sample that runs much faster so I added the second test to show how long it would take to have LINQ call the stored procedure just like the ADO.NET method and avoid the overhead of preparing the query. It seems that even though the original LINQ method is running the same query over and over it still has to carry out the preparation for the query each time. This is clearly an area that could be tuned prior to the .NET 3.5 release. In the meantime, the call to the stored procedure allows the new LINQ method to perform nearly as well as the ADO.NET version. If this particular method was performing poorly in a real application, breaking out the work to a stored procedure would be a good tuning option. But most of the time you will want to continue with inline LINQ queries so you get the productivity benefits that it provides through Intellisense and other features.

(more...)

Tuesday Presentation: Deeper in LINQ

Monday, August 13th, 2007

Tuesday night I will be presenting Deeper in LINQ for the Wisconsin .NET User Group. Below is the summary for the presentation.

Brennan Stehling will continue covering LINQ following Dave Bost's presentation earlier this year. This presentation will dig into more detail about querying databases, XML and collections of objects. The presentation will compare the performance of LINQ and ADO.NET queries and show the advantages of LINQ over conventional ADO.NET programming. The presentation will also look into databinding LINQ results to web forms in ASP.NET using the new LinqDataSource.

Since the presentation in January there have been some changes to LINQ. You can now get the Beta 2 release of the .NET 3.5 runtime and Visual Studio 2008. I will be doing a short review of the updated IDE before getting into the LINQ samples I have prepared. The presentation should answer all of your questions about LINQ and help you start using it right away.

For the meeting time and location, see the website. (www.wi-ineta.org)

Preparing for .NET 3.5

Monday, June 11th, 2007

The .NET 3.5 is coming fast. I have not really been terribly excited about it until this past week. I am starting to see things that are very interesting. I am already trying out LINQ with the CTP. The 3.5 release will be much more significant than the 3.0 release which essentially was just an augmentation of the framework. The 3.5 release will update the runtime and the compiler to support the new language features for C# and VB.NET.

To help you get your head around it you can could read this blog entry on .NET 3.5 which includes a diagram that lays out all of the changes. And to get a jump start on LINQ you can get into Blinq. You can simply point Blinq at a database and it will generate a new website with all of the code you need to update the data. The generated code is very useful as training material.

To immerse yourself completely in .NET 3.5 you can download and install Visual Studio "Orcas" which is currently marked as Beta 1. You can expect that there will be a Beta 2 as usual which will soon be followed by the final release by November. I would hope that the Beta 2 release comes within the next month or two.