【发布时间】:2018-01-08 09:54:23
【问题描述】:
我有一个带有按钮的菜单,每个按钮都有一个类别。在菜单旁边,我放置了一个列表框。此列表框链接到数据库中的产品列表。我希望每当我按下类别按钮时,链接到该类别(带有 categoryID)的产品都会显示在列表框中。
我使用以下代码在列表框中显示产品
var productslist = from products in db.products select products;
prodlb.ItemsSource = productslist;
【问题讨论】:
-
你没有尝试使用 where 过滤产品
from product in db.products where product.CategoryId = selectedCategoryId select product -
不起作用,product.categoryId 带有红色下划线
-
不要只是复制粘贴代码。理解逻辑。您在产品对象中有什么属性来表示它的类别?
-
我没有复制粘贴,但是 where 子句不起作用
-
我的代码有一个小错误。更新的是
from product in db.products where product.CategoryId == selectedCategoryId select product。试试这个。如果有错误,请在此处分享确切的错误。
标签: c# sql foreign-keys categories customer