Search code examples
c#linqreflector

Why Reflector ver 7 produced wrong Linq code like this


private FileStorageFolder GetCapsuleContentFolder(FileStorageDataContext db)
{
    IQueryable<FileStorageFolder> source = from dbFolder in db.FileStorageFolders
        where (dbFolder.ParentID == null) && (dbFolder.Purpose == reportFolderPurpose)
        select dbFolder into dbFolder
        join dbSubFolder in db.FileStorageFolders on dbFolder.ID equals 
        dbSubFolder.ParentID into dbSubFolder
         where (dbSubFolder.Purpose == capsulelayoutFolderPurpose) && 
        (dbSubFolder.FolderName == capsuleReportContent)
         select dbSubFolder;

Instrument.Assert(source.Count<FileStorageFolder>() == 1);
return source.Single<FileStorageFolder>();
}

this is not correct syntax.Does anyone know how to create IQueryable typed base on this?


Solution

  • If it is problematic, try cranking down the "Optimisation" setting to, say, .NET 2.0. This will then be forced to display the explicit .Select(...) etc. This should produce correct C#, but without the LINQ style.

    Note, however, that it may also reverse the apparent call-order, since it will probably use explicit extension-method representation. The code should be equivalent either way, though.