L’entité ne peut pas être construite dans une requête LINQ to Entities
Source : Stack Overflow
Vous ne pouvez pas (et ne devriez pas pouvoir) projeter vers une entité mappée. Vous pouvez cependant projeter vers un type anonyme ou vers un DTO :
public class ProductDTO
{
public string Name { get; set; }
// Other field you may need from the Product entity
}
Et votre méthode renverra une liste de DTO.
public List<ProductDTO> GetProducts(int categoryID)
{
return (from p in db.Products
where p.CategoryID == categoryID
select new ProductDTO { Name = p.Name }).ToList();
}