LINQ 哪里计数检查
所以我慢慢地了解 LINQ 语法,但是这个查询让我发疯..
我只想返回具有多个过滤器值的过滤器..我尝试在 fv 上放置一个 group by 但 p 超出了那么范围..
var filters = (from p in _db.Products
join pf in _db.ProductFilterSets on p.ProductID equals pf.ProductID
join fv in _db.FilterValues on pf.FilterValueID equals fv.FilterValueID
join f in _db.Filters on fv.FilterID equals f.FilterID
where products.Contains(p)
select f).Distinct();
我做错了什么?
我理想地需要:
var filters = (from p in _db.Products
join pf in _db.ProductFilterSets on p.ProductID equals pf.ProductID
join fv in _db.FilterValues on pf.FilterValueID equals fv.FilterValueID
join f in _db.Filters on fv.FilterID equals f.FilterID
where products.Contains(p) && fv.Count() > 1
select f).Distinct();
谢谢
So I'm slowly getting my head around the LINQ syntax, but this query's driving me nuts..
I only want to return filters with more than one filter value.. I've tried putting a group by on fv but p goes out of scope then..
var filters = (from p in _db.Products
join pf in _db.ProductFilterSets on p.ProductID equals pf.ProductID
join fv in _db.FilterValues on pf.FilterValueID equals fv.FilterValueID
join f in _db.Filters on fv.FilterID equals f.FilterID
where products.Contains(p)
select f).Distinct();
What am I doing wrong?
I ideally need:
var filters = (from p in _db.Products
join pf in _db.ProductFilterSets on p.ProductID equals pf.ProductID
join fv in _db.FilterValues on pf.FilterValueID equals fv.FilterValueID
join f in _db.Filters on fv.FilterID equals f.FilterID
where products.Contains(p) && fv.Count() > 1
select f).Distinct();
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以像这样编写查询,在 _db.FilterValues 上添加另一个联接,但使用
into
关键字将结果投影到一个组You can write the query like this, adding another join on the _db.FilterValues but projecting the result to a group by using the
into
keyword