sql - 如何编写具有多个连接的 linq
问题描述
作为初学者,我想获得以下一组查询作为 linq 并详细说明
//我的sql
select COL.title as organizationtitle,CL.[title] as
cousestitle,sum(FD.feathers) as totalfeathers,sum(FD.amount) as
totalamount
from [dbo].[FeathersDonated] FD
join [dbo].[Couses] C on FD.corpid=3 and FD.[cousesid]=C.id
join [dbo].[Couses_lang] CL on FD.[cousesid]=CL.cousesid and
CL.language='en-US'
JOIN [dbo].[Organization_lang] COL on COL.orgid=2 and COL.language='en
US'
group by FD.cousesid,CL.[title],CL.[description],COL.title
我尝试了以下一组代码。请帮忙
var featherDonated = _GoUoW.FeathersDonated.FindBy(x => x.corpid ==
param.corpid)
.GroupBy(x => x.cousesid).Select(x => new { cousesid = x.Key, amount =
x.Select(a => a.amount).DefaultIfEmpty(0).Sum(), feathers = x.Select(a =>
a.feathers).DefaultIfEmpty(0).Sum() })
.Join(_GoUoW.Couses.GetAll(), feather => feather.cousesid, couse =>
couse.id, (feather, couse) => new { feather, couse })
.Join(_GoUoW.Organization_lang.FindBy(orglang => orglang.language == "en-
US"), couses => couses.couse.orgid, orgid => (param.organizationid > 0 ?
param.organizationid : orgid.orgid), (couses, orgid) => new { couses,
orgid
})
.Join(_GoUoW.Couses_lang.FindBy(couselang => couselang.language == "en-
US"),
organization => organization.orgid.orgid, couselang => couselang.cousesid,
(organization, couselang) => new { organization, couselang })
.Select(x => new
{
x.organization.couses.feather.amount,
x.organization.couses.feather.feathers,
x.couselang.title
//x.organization.orgid.title,
}).ToList();
解决方案
推荐阅读
- jpa - Jakarta EE Persistence:数据库中未显示在 persistence.xml 中注册的新实体的表
- azure - 如何为 Azure 托管应用程序通知正确设置端点身份验证?
- python - keras 包内的语法错误
- button - 一旦点击 Woocommerce 下订单按钮状态
- node.js - 如何在 Node 和 Express 中设置模型路由的路径
- python - 在 CMIS Post 调用中,Python 时间戳值被发送为 None (Null)
- td-engine - 给定我的情景时,有没有办法评估 TDengine 的资源使用情况?
- sapui5 - 如何从我自己的后端系统为 UI5 应用程序使用 OData 服务?
- java - 通过 Java 中的 root 命令获取 Android 用户/设备信息
- python - ReadProcessMemory 一次扫描字符串