Mr.*_*ght 4 c# linq database sql-server
我在我的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
Run Code Online (Sandbox Code Playgroud)
我想将查询翻译成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}
Run Code Online (Sandbox Code Playgroud)
而且,我也无法得到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)
}
Run Code Online (Sandbox Code Playgroud)
另请检查此StackOverflow答案.
| 归档时间: |
|
| 查看次数: |
164 次 |
| 最近记录: |