EF框架的左连接

EF实现左连接时,一次只能实现一次左联。有时候会出现需要右连接的问题。此时,我的做法是在中间建立一张过渡的虚拟表。
var subQuery = from tt in deviceInfo
join t7 in deviceType on tt.deviceTypeId equals t7.id
into f
from fq in f.DefaultIfEmpty()
join t2 in distritCode on tt.provinceId equals t2.id
into b
from bq in b.DefaultIfEmpty()
join t3 in distritCode on tt.cityId equals t3.id
into c
from cq in c.DefaultIfEmpty()
join t4 in distritCode on tt.countyId equals t4.id
into d
from dq in d.DefaultIfEmpty()
select new DeviceParameter
{
id = tt.id,//设备Id号
indexCode = tt.indexCode,
deviceType = fq.chnName,
province = bq.chnName,
city = cq.chnName,
county = dq.chnName
};
var query = from t1 in alarmCase
join t2 in subQuery on t1.alarmId equals t2.id
into a
from aq in a.DefaultIfEmpty()
join t6 in deviceInfo on t1.robotId equals t6.id
into e
from eq in e.DefaultIfEmpty()
select new AlarmParameter
{
id = t1.id,
alarmIndexCode = t1.indexCode,
startTime = t1.startTime,
caseType = t1.caseType,
deviceId = t1.alarmId,
deviceType = aq.deviceType,
deviceIndexCode = aq.indexCode,
province = aq.province,
city = aq.city,
county = aq.county,
duration = t1.duration,
robotIndexCode = eq.indexCode, //机器人设备编号
status = t1.status
};
我们最终需要查询的内容是query,而subQuery是中间的虚拟表。有更简洁的做法请大佬指教,谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值