0

我有一个名为 Product 的表,它与 ProductCategory 有映射关系。我想在产品控制器中找到一个 ProductCategoryId。我怎样才能做到这一点。我在这里应用了 linq 查询,但我如何使用它来查找 productCategoryId。

var productCategoryId = (from ProductCategory in context.ProductCategories
                                             where (ProductCategory.ProductId==id)
                                           select ProductCategory);

现在我正在尝试从可能包含在 productCategoryId 中的数据库中找出一个 ID,但在这里无法访问它,例如,

var proCategoryId = _categoryService.GetProductCategoryById(productCategoryId);

我怎样才能找到实现这一目标。

4

1 回答 1

2
var productCategoryId = (from ProductCategory in context.ProductCategories
                         where ProductCategory.ProductId==id
                         select ProductCategory.ProductCategoryId).SingleOrDefault();
于 2012-07-28T10:17:24.790 回答