The type of the method to return ICollection<T>, but the request returns IEnumerable<T>(or IQueryable<T>). Most likely, you still do not need ICollection<T>, and if so, what do you expect from this collection? It cannot be used to manage the database. If all you do is query the database, change the type of the returned 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
};
}
source
share