IEnumerable<> to IList<>

Posted by nachid on Stack Overflow See other posts from Stack Overflow or by nachid
Published on 2010-04-28T09:00:19Z Indexed on 2010/04/28 9:03 UTC
Read the original article Hit count: 448

Filed under:
|
|

I am using Linq to query my database and returning a generic IList.

Whatever I tried I couldn't convert an IQueryable to an IList.

Here is my code.

I cannot write simpler than this and I don't understand why it is not working.

public  IList<IRegion> GetRegionList(string countryCode)
{
    var query = from c in Database.RegionDataSource
                where (c.CountryCode == countryCode)
                orderby c.Name
               select new {c.RegionCode, c.RegionName}; 

     return query.Cast<IRegion>().ToList(); 
}

This returns an list with the right number of items but they are all empty Please help, I am bloqued with this for a couple of days now

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ