+2  A: 

Will the query work without the where clause?

DevDave
@DevDave, you should really post that as a comment. That's the best way to delve for more information and the post an answer when you have one. Regardless, thanks for your question. Unfortunately, no I can't. The code base has moved on significantly since then and I can't roll-back that source file without impacting dependent files.
Lazarus
+1  A: 

Maybe I'm crazy, but your utility class shouldn't be outputting an IQueryable list. Your creating a local sequence that looks like it should be queryable. Ultimately, IQueryable lists should be delved out by your datacontext. If a utility class is creating a list, that should be returned as (most likely) an array or an IEnumerable, e.g.:

    public static readonly ISOCountry[] CountryCodes = new ISOCountry[] {
        new ISOCountry { isoCountryCode= "AF", Name= "Afghanistan"},
        new ISOCountry { isoCountryCode= "AX", Name= "Aland Islands"} 
        ...
    };

A local sequence can only be used in an IQueryable .Contains() statement. So, if you want to "mesh" your local sequence with your IQueryable sequence, you have to force the IQueryable to fire a SQL statement and grab the records it represents from the DB. To do that, all you have to do is iterate over the IQueryable records in some fashion:

IList<Competitor> competitorRecords =  competitorRepository
   .Competitors
   .Where(m => !m.Deleted)
   .OrderBy(m => m.countryId)
   .ToList(); //this fires the SQL statement

Once you've snagged the records from the db, you can create your list of ISOCountry records. Again, since this list isn't coming from your datacontext, it shouldn't be an IQueryable list. Instead, try this:

IList<ISOCountry> = competitorRecords
    .Join(CountryCodes, key1 => key1.countryId, key2 => key2.isoCountryCode, (competitors, codes) => new ISOCountry { isoCountryCode = competitors.countryId, Name = codes.Name })
    .ToList();

This will work, but you're probably grabbing unnecessary records from the database. It'd be even better if you could upload your ISOCountry list to the database. Once you do that, you'd be able to fire the query as you initially conceived it.

Hope this helps! Sorry you missed your deadline.

ewwwyn
You may be right about the IQueryable return, this utility function is used elsewhere and was originally designed to pull from a database, hence the IQueryable (and probably my incomplete understanding of the interface). I have now managed to get the function to complete by breaking it down in to parts and using IList but I am still very curious as to why the original query doesn't work and I think it should or should at least provide a better error message ;)
Lazarus