You method's return type is ICollection<T>
but the query returns an IEnumerable<T>
(or an IQueryable<T>
). Most likely you don't need an ICollection<T>
anyway, and if you did, what would you expect that collection to do? It couldn't be used to manipulate the database. If all you're doing is querying the database, then change the return type of your method to IEnumerable<T>
:
public IEnumerable<CourseDTO> MyMethod(int Id)
{
return from p in db.Students.Find(Id).Courses
select new CourseDTO
{
Id = p.Id,
CourseName = p.CourseName
};
}