[英]Comparing two counts in LINQ
hi have a simple query that compares all sent out requests to those that have been downloaded. 嗨,有一个简单的查询,将所有发送的请求与已下载的请求进行比较。
i have a tsql that works perfectly like so: 我有一个完全像这样的tsql:
select case when (select COUNT(*) from FileRecipient where File_ID = 3 and downloaded = 'Y')
= (select COUNT(*) from FileRecipient where File_ID = 3) then 'Y' else 'N' end
but would like to do it in LINQ. 但是想在LINQ中做到这一点。
any and all help would be appreciated. 任何帮助都将不胜感激。 i tried the following, but obviously i'm a long way away from getting it right. 我尝试了以下方法,但是显然我距离正确解决方案还有很长的路要走。 this just gives me the first of the two counts. 这只是给我这两个数中的第一个。 do i need to do two separate statements to get the second? 我是否需要做两个单独的语句才能得到第二个?
public static bool DownloadedByAll(int fsID)
{
using (SEntities ctx = CommonS.GetSContext())
{
var result = (from fr in ctx.FileRecipients
where fr.File_ID == fsID && fr.downloaded == "Y"
select fr.Recipient_ID).Count();
}
}
or would it just be simpler for me to use tsql within the entity framework for this? 还是对我来说在实体框架内使用tsql会更简单?
This should get you the result you need 这应该为您带来所需的结果
var result = ctx.FileRecipients
.Count(f=>f.File_ID == 3
&& f.downloaded == 'Y') == ctxt.FileRecipients
.Count(f=>f.File_ID == 3);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.