gpt4 book ai didi

c# - LINQ to Entities 无法识别方法组连接

转载 作者:行者123 更新时间:2023-11-30 20:37:22 25 4
gpt4 key购买 nike

如何解决这个错误?为什么会上涨?

Additional information: LINQ to Entities does not recognize the method 'System.Collections.Generic.List1[FRecipes.Models.Component]
ToList[Component](System.Collections.Generic.IEnumerable
1

public ActionResult ShowDishes(int id)
{
DishesWithCategory dish = new DishesWithCategory();
dish.category = id;
List<Item> Test = new List<Item>();
var result1 = (
from d in FRE.Dish
join c in FRE.Component on d.DishID equals c.DishID into items
select new Item { DishID = d.DishID, components = items.ToList() }
).ToList();

return View();
}

模型:

public class DishesWithCategory
{
public List<Item> item { get; set; }
public int category { get; set; }
}

public class Item
{
public int DishID { get; set; }

public string DishName { 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; }
}

最佳答案

尝试替换这一行:

select new Item { DishID = d.DishID, components = items.ToList() }

用这个:

select new Item { DishID = d.DishID, components = items }

错误很明显:ToList() 函数无法在该上下文中翻译。

关于c# - LINQ to Entities 无法识别方法组连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36228353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com