tags:

views:

19

answers:

1

I have the following Linq query:

var tmp = 
    from container in Container
    join containerType in ContainerType on container.ContainerType equals containerType
    where containerType.ContainerTypeID == 2
    select new { ContainerID = container.ContainerID, TypeID = container.ContainerTypeID};

var results = tmp.Select((row, index) => new { row.ContainerID, row.TypeID, ContainerIndex = index })

As is, this works fine. If I add the following, so I can see the results in LinqPad, I get the error described in the title of this message:

results.Dump();

This error is not a LinqPad error, it's coming from Linq, and I don't understand what it means.

Thank you.

+3  A: 

Okay, I hadn't realised Container was a LINQ to SQL data source to start with. Basically it's failing to convert the second projection to SQL.

So, you want to do just that bit in .NET instead - you can force it to use Enumerable.Select with AsEnumerable:

var results = tmp.AsEnumerable()
                 .Select((row, index) => new { row.ContainerID, row.TypeID,
                                               ContainerIndex = index });
Jon Skeet
@Jon - I'm sorry, I should have mentioned that. Thanks for your help.
Randy Minder