我在我的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#[加入多个表]
猜你喜欢
- Unity实现瞄准镜效果 2023-04-15
- C#-.NET Core 2从内存流下载Excel文件 2023-09-26
- C#实现文件上传及文件下载功能实例代码 2022-11-10
- c# – 在通用Windows应用程序中,如果视图模型中的属性发生更改,如何使用xaml更改按钮的背景颜色和数据绑定 2023-09-19
- C# 线程同步的方法 2023-03-09
- Unity3D UGUI特效之Image高斯模糊效果 2023-01-16
- ASP.NET Core部署到CentOS7,使用Nginx代理 2023-09-27
- C# FileStream简单介绍和使用 2023-01-22
- C#基于Socket的TCP通信实现聊天室案例 2023-05-17
- c# – 对Sql Server中的索引感到困惑 2023-11-12