2
Is there a right order to use Join? For example, I have two lists: Categories and products, should I first use the from clause with Categories or Products? And then in Join? Example:
var stockQuery = from category in categories
join product in products on category equals product.Category into prodGroup
select new { Key = category.Name, Products = prodGroup };
The code above works normally, but the code below does not, why?
var stockQuery = from product in products
join category in categories on product.Category equals category into prodGroup
select new { Key = category.Name, Products = prodGroup };
Shows the error that category
it’s not in the same context, but I still don’t understand why he’s not...
In addition: it would be possible to access the Join’s Category variable if the into clause did not need to be used. This clause hides the variables used to compose its result.
– Gabriel Rainha