Fabrice's weblog

Tools and Source

News


Read sample chapters or buy LINQ in Action now!
Our LINQ book is also available on AMAZON

.NET jobs

Emplois .NET

The views expressed on this weblog are mine alone and do not necessarily reflect the views of my employer. The content of this weblog is independent from Microsoft or any other company. transatlantys hot news

Contact

Me

Others

Selected content

Speaking for the Communauté .NET Montréal next Monday

In addition to speaking at DevTeach Montreal next week, Frédéric Schäfer and I will also give a demonstration of LINQ, Entity Framework and WPF in action to the Communauté .NET Montréal next Monday. This will be in French.
A bientôt à Montréal et DevTeach !

 

PS: Why should you go to DevTeach?

Posted: Nov 24 2008, 12:28 AM by Fabrice Marguerie | with no comments
Filed under: ,
IQToolkit, building your own LINQ IQueryable provider

Matt Warren, who provides the most detailed HOWTO for creating your own LINQ IQueryable provider, has now published a dedicated toolkit on CodePlex:

IQToolkit is essential if you are building your own LINQ IQueryable provider. It contains common tools and source code you can apply to your own project.
In the toolkit you will find useful techniques for manipulating LINQ expression trees, implementing IQueryable providers, and a host of extensible components for building providers that target translation of LINQ expressions into SQL like languages.

http://www.codeplex.com/IQToolkit

Creating a LINQ provider is not a walk in the park, but at least if you have to, you have everything you need at hand.


Cross-posted from http://linqinaction.net
Using the Select LINQ query operator with indexes

Yesterday, Fred asked me if I could help him to convert C# code to LINQ. The solution may not obvious to find unless you know LINQ well. I will reproduce here the solution I gave Fred. Whether the LINQ version of the code is easier to read than the original one is arguable. The purpose here is more to show LINQ's Select query operator in action.

Here is the original code:

int CountCorrectChars(string proposedValue, string correctValue)
{
  int correctCount = 0;
  for (int i=0; i < proposedValue.Length && i < correctValue.Length; i++)
    if (proposedValue[i] == correctValue[i])
      correctCount++;
  return correctCount;
}

Here is the LINQ version that I suggested:

int CountCorrectChars(string proposedValue, string correctValue)
{  
return correctValue
    .Select((testChar, index) => new {Character=testChar, Index=index})
    .Count(testChar => (testChar.Index < proposedValue.Length)
&& (testChar.Character == proposedValue[testChar.Index]));
}

As you can see, the LINQ version is not so easy to understand and is verbose. Of course, we could use shorter names, but that wouldn't change the complexity of the query. The LINQ version is not as good in terms of performance either... So, should we use LINQ or not? My point here is that LINQ is not a "one size fits all" solution. You should use it wisely and avoid complexifying code by choosing always to use LINQ.

What's interesting in this example, is also simply the use of Select with a two-parameter lambda expression. You may know the version of Select that takes a single-parameter lambda well, but its counterpart is less known (and used).

This is something that we cover in LINQ in Action in section 4.4.2. Here is what we write there, which gives another example of Select in action:

The Select and SelectMany operators can be used to retrieve the index of each element in a sequence. Let’s say we want to display the index of each book in our collection before we sort them in alphabetical order:

index=3         Title=All your base are belong to us
index=4         Title=Bonjour mon Amour
index=2         Title=C# on Rails
index=0         Title=Funny Stories
index=1         Title=LINQ rules

Here is how to use Select to achieve that:

Listing 4.15    Code-behind for the first ASP.NET page    (SelectIndex.csproj)
var books =
  SampleData.Books
    .Select((book, index) => new { index, book.Title })
    .OrderBy(book => book.Title);
ObjectDumper.Write(books);

This time we can’t use the query expression syntax because the variant of the Select operator that provides the index has no equivalent in this syntax. Notice that this version of the Select method provides an index variable that we can use in our lambda expression (precision not in the book: its not the name "index" that is important. You can use another name if you want. What makes the difference is that the lambda expression takes two parameters). The compiler automatically determines which version of the Select operator we want to use just by looking at the presence or absence of the index parameter. Notice also that we call Select before OrderBy. This is important to get the indices before the books are sorted, not after.

...One more tool in your toolbox. Now, use it wisely.

Update: Mark Sowul suggests a simpler solution:

return correctValue.Where((testChar, index) => index < proposedValue.Length && testChar == proposedValue[index]).Count();
Somehow I missed that Where overload. 

Cross-posted from http://LinqInAction.net

See you at TechEd EMEA in Barcelona next week

I'll be at TechEd in Barcelona next week. I'll be at the Ask The Experts booths a few hours during the week. Feel free to come and say hello. I'll be available if you want to discuss about LINQ, the LINQ in Action book, WPF and Silverlight, my projects, or .NET in general :-)

Please ping me if you'll be there too and would like to meet.


Cross-posted from http://linqinaction.net
Posted: Nov 04 2008, 12:42 AM by Fabrice Marguerie | with no comments
Filed under:
Speaking at DevTeach Montreal in December

DevTeach Montréal will take place this year between December 1 and 5. I have the pleasure to take part to this event and speak in no less than five sessions!

Here are my sessions, all in French:

  • Tout d'abord une série de quatre sessions que j'ai le plaisir de présenter avec Frédéric Schäfer. Il s'agit d'une reprise enrichie de notre session de l'Université du SI.
    Ces sessions vous permettrons de découvrir LINQ, Entity Framework, WPF, Silverlight et WCF en action.
    Il n'est pas nécessaire d'assister à l'ensemble des quatre sessions. Vous pouvez très bien n'assister qu'à certaines sessions. Nous fournirons un bref récapitulatif des épisodes précédents au début de chaque session.
    • Application Order Tracking - 1/4 - Créer un modèle métier testé avec Entity Framework et manipuler des données avec LINQ
    • Application Order Tracking - 2/4 - Développer une interface utilisateur riche et testable avec WPF en utilisant des design patterns
    • Application Order Tracking - 3/4 - Persister ses objets avec Entity Framework et adapter l'interface utilisateur en conséquence
    • Application Order Tracking - 4/4 - Développer une application Silverlight distribuée avec WCF
  • Je présente également une session en solo : Nouveautés des langages C# 3.0 et VB 9.0 (LINQ)
    Il s'agit d'une reprise de la session d'Introduction à LINQ, C# 3.0 et VB 9.0 que j'ai jouée avec Philippe Mougin durant les Microsoft TechDays France.
Frédéric présente une session en solo : Développement piloté par les tests.

Toutes les sessions sont détaillées sur le site de DevTeach.

Rendez-vous donc début décembre pour retrouver avec nous la fraîcheur de Montréal à cette époque et la chaleur de nos amis québécois !

Visual Studio Talk Show podcast about LINQ

In July, I was invited by Mario Cardinal and Guy Barrette to register a session for their Visual Studio Talk Show podcast. This session is now online. During one hour, Guy, Mario and I discuss about LINQ in French.

You can find the podcast here. I hope that you'll enjoy it and that it'll help you to learn more about LINQ's whats, whys and hows.

I'd like to thank Mario and Guy for giving me this opportunity. It was a very good experience!


Cross-posted from http://linqinaction.net
Posted: Sep 15 2008, 01:22 PM by Fabrice Marguerie | with no comments
Filed under: ,
LINQ im Einsatz, LINQ in Action in German

Today, I received a copy of LINQ im Einsatz. This is the German translation of LINQ in Action. It's now available from Amazon.de and from Hanser.

Bonus: The German version is bigger than the English one. It contains chapter 14, which covers LINQ to DataSet and is provided in English only as a PDF download from Manning's website.

Maybe we'll see translations in other languages next. French would be a good idea, for example ;-)

Viel Spaß beim Lesen!


Cross-posted from http://linqinaction.net
Proagora.com redesigned and services announced

We have just redesigned proagora.com to improve usability. We have also announced the complete set of services that the site offers and the corresponding rates.

The good news is that we have decided to keep the website free! Of course, everything is still free for experts, but services for companies, such as posting jobs, also remain free! All the details are available on the page that presents the services provided by proagora.com (same in French).

Regarding the new design, we took inspiration from LinkedIn, especially for the main menu. We also removed useless text and tried to simplify everything. For example, we now have a new home page, which content depends on the user (anonymous, expert, company).

proagora.com French home pageproagora.com English home page

We hope that you'll find the site easier to use than before. Feel free to create your .NET/Java expert profile or post jobs if you're hiring.

.NET 3.5 SP1 LINQ improvements

In May, I announced the changes related to LINQ that were included in .NET 3.5 Service Pack 1 Beta. Now that the SP1 is officially available, more changes have been announced.

The originally announced changes were:

  1. The support for SQL Server 2008
  2. The release of a new flavor of LINQ: LINQ to Entities, which comes with the ADO.NET Entity Framework

Dinesh Kulkarni announces new changes:

  1. Performance improvements for LINQ to Objects queries
  2. Cast<T> breaking change
  3. Performance improvements for LINQ to SQL

Cross-posted from http://linqinaction.net
The greatest thing since google.com: goosh.org, the unofficial Google command line

If you want to experience Google's search differently, head to http://goosh.org. You'll be able to search Google from a web command line. It's simple and fast.

goosh.org

Here is how to get started:

  1. type your search keywords and press ENTER
  2. hit ENTER again or type m for more results
  3. type a result's number or click on its link to navigate to it
  4. type h or man to learn more about what's possible
Posted: Jun 30 2008, 07:01 PM by Fabrice Marguerie | with no comments
Filed under: ,
More Posts Next page »