書き込み方法Description
Recipe
からrecipe=
までです。 join r in Recipe on d.DishID equals r.DishID
を使ってみましたが、間違った結果が出ました。 result1の項目を1つ消去します。Linqグループ参加
Exptected出力:
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
List<Component> Component = new List<Component>();
List<Dish> Dish = new List<Dish>();
List<Recipe> Recipe = new List<Recipe>();
Dish.Add(new Dish { DishID = 9, CategoryID = 6, DishName = "Pork" });
Dish.Add(new Dish { DishID = 10, CategoryID = 6, DishName = "Beef" });
Component.Add(new Component { ComponentID = 1, DishID = 9, AmountID = "1", NameID = "1" });
Recipe.Add(new Recipe { DishID = 9, RecipeID = 0, Description = "Test" });
var result1 = (
from d in Dish
//join r in Recipe on d.DishID equals r.DishID
join c in Component on d.DishID equals c.DishID into items
select new Item { DishID = d.DishID, components = items.ToList() recipe=}
).ToList();
}
}
public class Item
{
public int DishID { get; set; }
public string DishName { get; set; }
public string recipe { get; set; }
public List<Component> components { get; set; }
}
public partial class Component
{
public int ComponentID { get; set; }
public int DishID { get; set; }
public string AmountID { get; set; }
public string NameID { get; set; }
}
public partial class Dish
{
public int DishID { get; set; }
public int CategoryID { get; set; }
public string DishName { get; set; }
}
public partial class Recipe
{
public int RecipeID { get; set; }
public int DishID { get; set; }
public string Description { get; set; }
}
}
「それは間違った結果をもたらします」とは何ですか?サンプル入力?期待される出力? – Eser
あなたのコードを実行するように修正してください、今はあなたが言っていたものではなく、linqで左結合を行う方法についての答えを出しましたが、あなたのコードはコンパイルされず、現在働いているコードを表示します – konkked
調理法=>レシピ1から1への関係?あなたの編集は私を混乱させました – konkked