You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在linq2db复杂查询中避免重复使用LoadWith方法

Linq2db 避免重复预加载关联路径的方法

你可以在同一个LoadWith调用后,连续使用多个ThenLoad来加载PostComments的多个关联表,无需重复声明父级关联路径:

db.Posts
   .LoadWith(p => p.PostComments)
       .ThenLoad(pc => pc.CreatedUser)
       .ThenLoad(pc => pc.UpdatedUser);

linq2db的LoadWith会返回对应关联的加载配置器,在这个配置器上连续调用ThenLoad,就能为同一个父关联(这里是Post.PostComments)加载多个子关联对象,完全替代你之前重复调用LoadWith的写法,效果一致且更简洁。

内容的提问来源于stack exchange,提问作者MrD at KookerellaLtd

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 15:15:53