我在我的sql server中处理这个查询select a.care_type_id, a.description,isChecked = case when b.care_type_id is null then false else true endfrom caretype aleft join patientinsurancetacitem b on a...

我在我的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.但是,我和操作符有问题.到目前为止我有这个代码;
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}
而且,我也无法得到我在isChecked变量中等同的b.从哪里开始修改以获得与我的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)
}
另请查看this StackOverflow answer.
织梦狗教程
本文标题为:SQL查询到LINQ C#[加入多个表]


基础教程推荐
猜你喜欢
- UGUI实现随意调整Text中的字体间距 2023-01-16
- c# 静态类的使用场景 2023-03-28
- 改进c# 代码的五个技巧(二) 2023-03-28
- c# Winform自定义控件-仪表盘功能 2023-01-28
- C# winform跨线程操作控件的实现 2023-06-14
- C# 操作网络适配器的示例 2023-03-13
- C# 获取IP及判断IP是否在区间 2022-10-28
- C#事件(event)使用方法详解 2022-12-09
- Unity Shader实现3D翻页效果 2023-04-26
- c# 实现发送邮件的功能 2023-03-03