Can you revert back to IList <T>?
In my service level for my MVC application, I am trying to convert linq to sql results into objects of my business model. I am currently trying to execute the following code:
public IList<Project> GetAllProjects()
{
var results = from p in _context.Repository<DBMappings.project>()
select p;
foreach (DBMappings.project prj in results.ToList<DBMappings.project>())
yield return CreateProjectEntityFromDBProject(prj);
}
Unfortunately, this does not work, and the only thing I can guess is that the output only works with IEnumerable. Is there any other solution besides creating a new list, adding elements to the foreach loop and returning the list? I need to use IList, because methods that use the returned list should be able to execute list methods such as .Sort ().
IList<T>describes functionality that is incompatible with IEnumerable<T>, at least until lazy loading.
The ability to go to a specific a la index IList<T>requires that the entire listing be “listed”, at least up to the specified index.
If you don’t need to evaluate everything IEnumerable<T>, you can build List<T>by taking a IEnumerable<T>constructor parameter, and then return List<T>asIList<T>