这是查询在SQL中的外观:
select count(SnpId_this), DrugId, VariantId from tbl_custom_SNPs_All
join tbl_custom_SNP_Variants on VariantId = SnpsVariantId_this
join tbl_custom_SNP_Drugs_Apelon_NUIs on DrugId = SnpsDrugId_this
group by DrugId, VariantId
这是我使用linq-to-sql的尝试:
var drugVariantGroups =
(from a in adminDB.tbl_custom_SNPs_Alls
join v in adminDB.tbl_custom_SNP_Variants
on a.VariantId equals v.SnpsVariantId_this
join d in adminDB.tbl_custom_SNP_Drugs_Apelon_NUIs
on a.DrugId equals d.SnpsDrugId_this
group a by new { a.VariantId, a.DrugId } into dv
select new
{
dv.Key.VariantId,
dv.Key.DrugId,
Entries = dv.Sum()
}).ToList();
看起来dv没有求和的定义。如何访问SnpId_this进行计数?
最佳答案
只需使用Count
。如果可能,您可能需要过滤SnpId_this
为null的所有条目,并精确匹配T-SQL。
Entries = dv.Where(t => t.SnpId_this != null).Count()