我正在我的SQL Server中处理此查询
select a.care_type_id, a.description,
isChecked = case when b.care_type_id is null then 'false' else 'true' end
from caretype a
left join patientinsurancetacitem b on a.care_type_id = b.care_type_id and
b.tac_id = 1
我想将查询转换为LINQ。但是,我在and
操作员方面遇到了麻烦。到目前为止,我已经有了这段代码;
from a in context.CareTypes
join b in context.PatientInsuranceTACItems on a.care_type_id equals
b.care_type_id into x
from xx in x.Where(w => w.tac_id == 1).DefaultIfEmpty()
select new {
isChecked = (b.care_type_id == null ? false : true),
care_type_id = a.care_type_id,
description = a.description}
而且,我也无法获得b
等于isChecked
变量的变量。我将从何处开始修改以获得与sql查询相同的结果?在哪里我弄错了?
试试这个
from a in context.caretype
join b on context.patientinsurancetacitem
on new { CA = a.care_type_id, CB = 1} equals
new { CA = b.care_type_id, CB = b.tac_id}
into tmp from b in tmp.DefaultIfEmpty()
select new
{
care_type_id = a.care_type_id,
description = a.description,
checked = (b != null) // Or ((b == null) ? false : true)
}
还要检查此StackOverflow答案。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句