【发布时间】:2014-12-18 22:49:59
【问题描述】:
我正在运行这个 Linq 查询:
var patientList = from p in db.Patients
where p.ClinicId==11
select p.Id;
var patientswithplan = from p in db.Plans
where patientList.Contains(p.PatientId)
select p;
它返回 1030 个结果。
但是当我想出这个查询时,我首先用 sql 编写它来测试它,这会显示 956 个结果
select id from patients where clinicid=11
and id in(select patientid from plans)
order by id
我以为这些查询是一样的,有什么区别,哪个是正确的?
【问题讨论】:
-
第一个从db.Plans中选择,第二个从db.Patients中选择。
-
有什么区别?是否有重复的结果,或者只是在 C# 中而不是在 SQL 中检索的记录?
标签: c# asp.net linq linq-to-sql