First, I think your code will not compile, you’re missing two parentheses:
return (from c in db.RecipeIngredients
join d in db.Ingredients on c.IngredientID equals d.IngredientsID
where c.RecipeID.Equals(recipeID)
select (d.IngredientsID,c.Unit,c.IngredientID,c.Amount)).ToList();
Ok, next, (d.IngredientsID,c.Unit,c.IngredientID,c.Amount)
if you’re on C# 7.0 that’s a declarative tuple with all the variables, so you need to return that types between parentheses, like here (I will assume the types of your vars, correct it as needed):
public List<(int, UnitNames, int, double)> GetRecipe(int recipeId)
{
return (from c in db.RecipeIngredients
join d in db.Ingredients on c.IngredientID equals d.IngredientsID
where c.RecipeID.Equals(recipeID)
select (d.IngredientsID,c.Unit,c.IngredientID,c.Amount)).ToList();
}
To access the variables you acces like this:
var recipe = GetRecipe(recipeId);
foreach(var ingredient in recipe)
{
var ingredientsId = ingredient.Item1;
var unit = ingredient.Item2;
var ingredientId = ingredient.Item3;
var amount = ingredient.Item4;
}
In any case, I would recommend to create a class to pass the data, it will result in a much clear code:
public class Ingredient
{
public int IngredientsId { get; set; }
public UnitNames Unit { get; set; }
public int IngredientId { get; set; }
public double Amount { get; set; }
}
public List<Ingredient> GetRecipe(int recipeId)
{
return (from c in db.RecipeIngredients
join d in db.Ingredients on c.IngredientID equals d.IngredientsID
where c.RecipeID.Equals(recipeID)
select new Ingredient {
IngredientsId = d.IngredientsID,
Unit = c.Unit,
IngredientId = c.IngredientID,
Amount = c.Amount
}).ToList();
}