3 Answers
3

This is not really a problem that can be solved by "casting"; the result of the query you've got isn't a list - it's a deferred-executing sequence that will stream the matching items out on demand. You will have to actually load these results into aList<T>to achieve your purpose. For example, the Enumerable.ToListmethod will create a new list, populate it with the results of the query and then return it.

Thanks! I just thought of something - deffered execution. These queries will not execute until they are enumerated. I am building these into a DataLayer that returns the queries. Suppose I pick your first one and have:public List<Entities.Base> GetBasesForFieldOfficeCD(string officeCD) { List<Entities.Base> bases = this.GetAllBases(); List<Entities.Base> thebases = (from aBase in bases where aBase.OfficeCD == officeCD select aBase).ToList(); return thebases; } –Do I need to enumerate/execute the queries before return?
– Sam GentileOct 22 '10 at 17:04

ToList() will do the enumeration for you. The final result: a 'normal' data-structure, not a query. Basically, a list doesn't remember how it was created. On the other hand, you may prefer that your GetBasesForFieldOfficeCD method return a deferred-executing query instead. In this case, make the return type 'IEnumerable<Entitities.Base>` and remove the call to ToList().
– AniOct 22 '10 at 19:45

I don't think he wants a select new Entities.Base because that creates all new objects with the same contents as the old objects. He most likely wants the same objects to populate both lists.
– GabeOct 22 '10 at 16:53

@Gabe - Possibly. I agree with Ani's answer (hence the credit), but wanted to put forth a different option for consideration.
– Joel EthertonOct 22 '10 at 16:57