If you are not at all interested in zeros in your products, you can add a condition where
var productTypes = from ProductDto e in Product
where e.Product.ID != null
select new
{
Id = e.Product.ID,
Name = e.Product.name
};
If you need zeros, use the following command:
var productTypes = Product.Select( prod => {
if (prod.ID != null)
{
return new { ID = prod.ID, Name = prod.Name };
}
else
{
return null;
}
} );
source
share