I am getting an error message that says:
"No mapping exists from object type <>f__AnonymousType6`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] to a known managed provider native type."
public List<Product> GetCategoryProducts(int catID)
{
string sql = @"select p.ProductID, p.ItemName, p.ImageName
from Product p, ProductCategory pc
where p.ProductID = pc.ProductID
and pc.CategoryID = @catID
order by p.ItemName";
List<Product> products = db.Products.SqlQuery(sql, new { catID }).ToList();
return products;
}
I am not sure why I am getting this error
SqlQuerymethod help. But why bother with SQL, this is quite simple LINQ To Entities query, you are not using the benefits of your ORM.