Linq Where子句有两个条件,不起作用
我有三张桌子:Linq Where子句有两个条件,不起作用,linq,Linq,我有三张桌子: [Products] Id Title Info Price [ProductCategories] Id Title ParentId [ProductsInCategories] Id ProductId ProductCategoryId 我试图阅读某一类别的一系列产品。我的代码没有对ProductCategoryId进行简化,只是从Product表中加载所有产品。我的错在哪里 id变量是
[Products]
Id
Title
Info
Price
[ProductCategories]
Id
Title
ParentId
[ProductsInCategories]
Id
ProductId
ProductCategoryId
我试图阅读某一类别的一系列产品。我的代码没有对ProductCategoryId进行简化,只是从Product表中加载所有产品。我的错在哪里
id变量是一个方法参数。输入的值是正确的
var ProdInCat = from p in _context.Products
from pc in _context.ProductsInCategories
.Where(x => p.Id == x.ProductId && x.ProductCategoryId == id)
.DefaultIfEmpty()
select new
{
p.Id,
p.Title,
p.Info,
p.Price
};
使用内部联接表达式
var ProdInCat = from p in _context.Products
from pc in _context.ProductsInCategories.Where(x => x.ProductCategoryId == id).DefaultIfEmpty()
on p.Id equals pc.ProductID
select new {
p.Id,
p.Title,
p.Info,
p.Price
};
使用内部联接表达式
var ProdInCat = from p in _context.Products
from pc in _context.ProductsInCategories.Where(x => x.ProductCategoryId == id).DefaultIfEmpty()
on p.Id equals pc.ProductID
select new {
p.Id,
p.Title,
p.Info,
p.Price
};
您可以根据您的外部(计算)
id
将产品与筛选后的产品列表合并到类别中
from p in _context.Products
join pc in _context.ProductsInCategories.Where(pic => pic.ProductCategoryId == id).DefaultIfEmpty()
on p.Id equals pc.ProductId
有关如何实现此目的的更多信息,请访问以下链接:您可以根据外部(计算的)
id
将产品与经过筛选的产品列表合并到类别中
from p in _context.Products
join pc in _context.ProductsInCategories.Where(pic => pic.ProductCategoryId == id).DefaultIfEmpty()
on p.Id equals pc.ProductId
有关如何实现这一点的更多信息,请访问以下链接:在引入pc之后,您在查询中根本没有使用它。我觉得这是个错误。看起来这应该是一个连接或组连接。引入后,您在查询中根本没有使用
pc
。我觉得这是个错误。看起来这应该是一个连接或组连接。