LINQ query returns empty list

Topics: Writing modules
Dec 4, 2011 at 2:52 PM
Edited Dec 4, 2011 at 9:23 PM

Hi All,

I'm getting stuck with the LINQ query. I have the following classes:

    public class CityRecord
    {
        public virtual int Id { get; set; }
        public virtual string Name { get; set; }
        public virtual CountryRecord Country { get; set; }

        [CascadeAllDeleteOrphan]
        public virtual IList<CityDistrictRecord> Districts { get; set; }
    }

    public class CountryRecord
    {
        public virtual int Id { get; set; }
        public virtual string Name { get; set; }
        public virtual ContinentRecord Continent { get; set; }

        [CascadeAllDeleteOrphan]
        public virtual IList<CityRecord> Cities{ get; set; }
    }

    public class ContinentRecord {
        public virtual int Id { get; set; }
        [Required]
        public virtual string Name { get; set; }
        public virtual string Description { get; set; }
    }

Why the following query returns empty list?

var cities = (from city in _cityService.GetCities()
where city.Country.Continent.Id == model.SelectedContinentId
select new CityInQueueViewModel
{
     Name = city.Name,
     ...
}).ToList();

Thanks in advance.

Coordinator
Dec 5, 2011 at 1:56 AM

Attach a debugger and find out. Is GetCities returning anything?

Dec 5, 2011 at 4:22 PM

Sorry. That was my own issue.

The code above works ok.