Tracking Down a Stack Overflow in My Linq Query
- by Lazarus
I've written the following Linq query:
IQueryable<ISOCountry> entries = (from e in competitorRepository.Competitors
join c in countries on e.countryID equals c.isoCountryCode
where !e.Deleted
orderby c.isoCountryCode
select new ISOCountry() { isoCountryCode = e.countryID, Name = c.Name }).Distinct();
The objective is to retrieve a list of the countries represented by the competitors found in the system. 'countries' is an array of ISOCountry objects explicitly created and returned as an IQueryable (ISOCountry is an object of just two strings, isoCountryCode and Name). Competitors is an IQueryable which is bound to a database table through Linq2SQL though I created the objects from scratch and used the Linq data mapping decorators.
For some reason this query causes a stack overflow when the system tries to execute it. I've no idea why, I've tried trimming the Distinct, returning an anonymous type of the two strings, using 'select c', all result in the overflow. The e.CountryID value is populated from a dropdown that was in itself populated from the IQueryable so I know the values are appropriate but even if not I wouldn't expect a stack overflow.
Can anyone explain why the overflow is occurring or give good speculation as to why it might be happening?
EDIT
As requested, code for ISOCountry:
public class ISOCountry
{
public string isoCountryCode { get; set; }
public string Name { get; set; }
}