Microsoft LINQ Books

Programming Microsoft LINQ & Introducing Microsoft LINQ
Welcome to Microsoft LINQ Books Sign in | Join | Help
in Search

Marco Russo

  • Corrections for Programming Microsoft LINQ book

    We just published an updated version of the corrections for the Programming Microsoft LINQ book.

    You can download it from this link.

  • New templates for LINQ to SQL code-generation

    Damien posted a new version of his templates to improve code-generation of classes for LINQ to SQL, including a short screen-cast that explain how to use it. Valuable resource if you use LINQ to SQL!

  • LINQ and Tuples in .NET 4.0

    .NET 4.0 will add the concept of Tuples in the Base Class Library, that will improve interoperability between languages such as F# or IronPython and C# or Visual Basic. LINQ will not have big changes in .NET 4.0, but only some lifting to support new features: for example, the Zip operator will be added in System.Linq.Enumerable to combine two collections generating an ordered sequence of Tuples (that you can then project in a different way). Some good examples are described in this post by Matthew Podwysocki.

  • Updateable LINQ

    Bart de Smet wrote a very interesting post about the possible creation of an Updateable LINQ provider, especially if it can be used for a SQL dbms (of course it would work with LINQ to SQL but it should be applicable to LINQ to Entities too). I like this approach very much.

    However, a Microsoft word on this, especially defining the "official" LINQ extensions and interfaces to implement an updatable query provider, would be fundamental to write code that will be still valid when a different LINQ provider implementation will be used.

  • LINQ to SQL vs LINQ to Entities - decisions from ADO.NET team

    To make a long story short: the ADO.NET team is now responsible of ADO.NET Entity Framework (including LINQ to Entities) and of LINQ to SQL (the last one was originally in charge of the a separated team, tied to the C# compiler).

    There is an evident overlapping between LINQ to SQL and LINQ to Entities and since the first day, Microsoft said that in the long run, these two solutions would have been merged into a single one.
    Now, the roadmap that is arising is: Entity Framework will be improved adding features that will be necessary to cover scenarios where LINQ to SQL today is preferred over LINQ to Entities and Entity Framework.

    There are a lot of comments - I suggest you starting here to get a good recap and pointers to many others.

    My personal opinion is that LINQ to SQL is very good in some scenarios and should not be dropped until a good alternative (in EF?) is available. For example, I use LINQ to SQL to implement nightly processes that are part of ETL solutions. In these cases, I use LINQ to SQL to read data (expecially configuration data, but sometimes also source data) and use the SqlBulkCopy API to write data into destination tables. Having all the necessary into a single executable file, without external dependencies, is a big advantage for deployment (a single file to copy). Today LINQ to Entities would be slower, would have more files and would require .NET 3.5 SP1 on production servers (the last one would not be a real issue in my case). There are of course other scenarios when there is something that makes LINQ to SQL a better choice against the current version of Entity Framework.

    My hope is that a convergence of two partially overlapped frameworks is good, but at the same time this shouldn't be a penalization for the current users of the "losing" part. This will require several releases of .NET to be done, and I hope that in the meantime the LINQ to SQL engine will have a decent evolution to keep its current position of "light LINQ oriented DAL replacement to SQL Server".

  • Book signing @ PDC 08

    If you are at PDC 2008, I'll be at book signing for Programming Microsoft LINQ at bookstore on Tuesday 28, during the coffee break between 3:00 and 3:30 PM.
    I and Paolo will be happy to meet you and receive your direct feedback about our LINQ book.

  • Use IEnumerable as a source for SqlBulkCopy

    Today I needed to use SqlBulkCopy class passing an IEnumerable<T> as a source instead of a IDataReader. Before writing something that someone else could have already written, I made some search and I found this interesting post that solve exactly this issue. In the post there is also a link to source code. Take also a look at performance optimization for getter as described in post comment.

  • Non-boolean LINQ predicates

    Bart De Smet just wrote a long post about LINQ predicates that can be defined without returning a boolean value.

    This is something I partially evaluated writing the Programming Microsoft LINQ book, but in his post Bart goes very deep on this topic and shows a lot of interesting details and ideas.

  • Active queries LINQ

    Paul Stovell made a presentation on "Reactive Programming and Bindable LINQ" at TechED Australia 2008 (unfortunately, I was at the antipode in Italy, but the topic is really interesting). I didn't know there are projects somewhat similar to Bindable LINQ in CodePlex: Obtics and Continuous LINQ. I really like the idea of defining "live" queries with LINQ.

  • LINQ to SQL and the procedure cache of SQL Server

    I just received a mail from Adam Machanic that pointed me to this bug (I would call it a performance issue) about the construction of SQL statements generated by the LINQ to SQL engine.

    The issue: every string passed as a constant in the query will be auto-parameterized using the length of the passed string, even when you used a string variable into the LINQ query. If you write something like

    string s = "Wine";
    var query =
            from x in db.Products
            where x.ProductName == s
           
    select x;

    you will see that a parameter of type NVARCHAR(4) will be passed to the generated SQL query. The next execution of query might contain a different value in the s parameter, and for this reason a different parameter type might be used: if the length of the string in the s variable changes, then the same query will be sent to SQL Server, but using a different type in the sp_executesql parameters .For example, a NVARCHAR(5) would be used whether s contains"Bread".

    The consequence of this behavior is that you could have a non-optimal performance from SQL Server and, more important, the procedure cache could be filled up with several copies of the same query, differing each other only in the length of the parameter type.

    I agree with Adam: this is something to be fixed. But my suspect is that we will get a "by design" answer another time...

  • IQueryable under the cover

    In the Programming Microsoft LINQ book we dedicated two whole chapters (76 pages) about the writing of a IQueryable LINQ provider: one is about expression trees and the other covers the several ways to extend LINQ, including the writing of an IQueryable provider. I know that the subject is complex and probably is not necessary to every programmer. However, a good understanding of what happens under the cover of an IQueryable provider is good for everyone using any flavor of LINQ: when you debug your code, it might help you in finding issues faster.

    I wrote this introduction just to explain why you should read this post of Bart De Smet, which is undoubtedly shorter than the corresponding chapter of our book and gives you a very good step-by-step introduction of the inner workings of an IQueryable LINQ provider. Then, if you really like this kind of things, you have another good reason to read the book :-)

  • Important LINQ Changes in .NET 3.5 SP1

    Dinesh Kulkarni wrote an important post about changes in LINQ introduced by .NET 3.5 SP1 that has been released yesterday.

    One of the interesting changes is in the Cast<T> operator and its behavior is better described in this post by Ed Maurer. I think that the side effects of this change should be limited, because the use of explicit type for the range variable in a query expression (i.e. from int n in numbers select... instead of from n in numbers select...) is not very common. In fact, I don't remember examples of its usage in our Programming LINQ book. Take care of this change if you used (or will use) this syntax.

  • Dangerous use of ArrayList in Lambda Expressions

    I have just validated this bug posted on Connect. It seems a compiler issue, I'd like to read a Microsoft answer about this.

    However, the general issue is that using ArrayList in a lambda expression with a collection initializer could be dangerous. There are not so many reasons to use an ArrayList in a lambda expression, unless you are refactoring or working with legacy code that cannot be modified upgrading ArrayList to generic collections.

  • The adoption of LINQ

    Eric White has written an interesting post titled "Are developers using LINQ?" - there are interesting considerations about the adoption of functional programming too, but the most interesting part for me is the list of comment of the post. A lot of people described the adoption of LINQ into their team or company, and there is a spread variety of comments (good and bad).

    An interesting comment is about the future adoption of F# when it will be shipped, because of the complete adoption of functional programming (C# 3 is not a complete functional programming like F# is). I suggest you to take a look at this post and its comments, because it gives you an idea of what is going on out there.

  • Multiple Results with LINQ to SQL

    I just read a post about getting multiple results with LINQ to SQL without using stored procedures. This technique is interesting when you have multiple queries returning a few rows each one and you want to save time by skipping some roundtrip between your program and SQL Server. Looking at the post, I immediately thought that it would be interesting comparing this solution with an asynchronous one, executing each query in a different thread. I don't have time to make some benchmark, but it would be interesting to make a comparison between these two techniques.

More Posts Next page »
Powered by Community Server (Personal Edition), by Telligent Systems