gpt4 book ai didi

asp.net-mvc-3 - 包含路径表达式必须引用在类型上定义的导航属性

转载 作者:行者123 更新时间:2023-12-02 00:14:37 25 4
gpt4 key购买 nike

我有两个模型说"Page""Product" Product's PageID 指的是Page's ID

在我的产品索引 View 中,我需要将页面列表作为下拉列表,因为我正在使用

public ViewResult Index()
{
var products = _db.Products.Include(p => p.Page);
return View(products.ToList());
}

但我只需要那些 PageGroup 属性值为 'Product' 的页面。为此,我使用了

public ViewResult Index()
{
var products = _db.Products.Include(p => p.Page.PageGroup
.Contains(PageGroup.Product.ToString()));
return View(products.ToList());
}

报错如下:

The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties. Parameter name: path

最佳答案

代替

var products = _db.Products.Include(p => p.Page.PageGroup.Contains(PageGroup.Product.ToString()));

你想要这样的东西。

var products = _db.Products.Include(p => p.Page).Where(p => p.Page.PageGroup.Contains(PageGroup.Product.ToString());

您可能需要包含更多子属性(如 PageGroup)来检查您的实际情况,但如果不了解您的数据模型,我不能肯定地说。

关于asp.net-mvc-3 - 包含路径表达式必须引用在类型上定义的导航属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13854033/

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