[英]Linq for distinct count
I'm not sure how to do this, I have this part of a query: 我不确定如何执行此操作,我有查询的这一部分:
let DistinctHits = db.tblTrackerVisits
.Where()
.Select(d=>d.IPID)
.Distinct()
.Count()
There is a table called db.tblTrackerVisitVariables
: 有一个名为db.tblTrackerVisitVariables
的表:
What I'm trying to do is modify the query above so that it only counts the distinct records where one of the relating tblTrackerVisitVariable
records has a VariableID
of n
. 我正在尝试做的就是修改上面的查询,以便它只计算不同的记录,其中相关的tblTrackerVisitVariable
记录之一的VariableID
为n
。
An pseudo example that might make it clearer: 一个伪示例可以使它更清晰:
let DistinctHits = db.tblTrackerVisits
.Where(d=> db.tblTrackerVisitVariables.where(v=>v.VisitID == d.ID AND v.VariableID == n))
.Select(d=>d.IPID)
.Distinct()
.Count()
Perhaps something like the following: 也许像下面这样:
let DistinctHits = db.tblTrackerVisits
.Where(d => d.tblTrackerVisitVariables.Any(v => v.VariableID == n))
.Select(d => d.IPID)
.Distinct()
.Count()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.