Entity Framework: How to bind related products
- by Waheed
I am using the following Linq query
from p in Product.Include("ProductDetails.Colors")
where p.ProductID.Equals(18)
select p;
And then using the result of this query to bind the GridView.
The productDetails are bind to the grid fine, but the Colors are not bind. To bind colors i am using <%# Eval("Colors.CategoryName") %. Error is " Field or property with the name 'Colors.CategoryName' was not found on the selected data source."
But in a loop i am getting this fine.
foreach (ProductDetails proDet in pd.ProductDetails)
{
string bar = proDet.BarCode;
string color = proDet.Colors.CategoryName;
}