I have a feeling the following might be an atrocity, and maybe that's why it doesn't work. So here I am, asking for your help. :-)
Also please help me edit this question. I do not know what would be an appropiate title for it or a better way to formulate it. (Like you have probably guessed by now, English is not my native language).
Consider a class like:
public class Order { public int FareCode; public int Quantity; } Then a Linq query like:
var orders = new []{ new Order {...}, ...}; var fareCodes = orders.Select(o => o.FareCode).ToArray(); using(var dc = new datacontext()) { var query = dc.Fares .Where(f => fareCodes.Contains(f.FareCode)) .Select(f => new { Fare = f, Quantity = orders.Single(o => o.FareCode == f.FareCode).Quantity //<-- This is not right! }) } So Quantity = Orders.Single(o => o.FareCode == f.FareCode).Quantity ins't right. So what would be another option to accomplish this?
UPDATE: The reason it does not work is because the runtime throws this exception: Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator