c# - 如何加入三个table rest api .net core 5?
问题描述
我有三个实体。
第一个 x 第二个 y 第三个 z
public int Id { get; set; }
public ICollection<y> y{ get; set; }
public virtual z z{ get; set; }
For Y
public int Id { get; set; }
public int xID{ get; set; }
public x x { get; set; }
FOR Z
public int Id { get; set; }
public int xId { get; set; }
public x x { get; set; }
当我尝试返回 await _context.x.ToListAsync(); y 和 z 列为空。这是为什么?如何相互连接?
我使用流利的 api 来建立关系。
其实我需要这个查询。如何写异步?
select table1.ID ,table1.Name from Table1 inner join Table2 on Table1 .ID =Table2 .ID
inner join Table3 on table2.ID=Table3 .ID
解决方案
你错过了一些Include()
电话。
您的查询应该是
await _context.x.Include(e => e.y).Include(e => e.z).ToListAsync();
推荐阅读
- ios - IOS/Objective-C:无结果时在tableview的背景视图中显示消息
- ajax - document.fonts.ready.then 为什么考虑同步 XMLHttpRequest
- hadoop-yarn - taskmanager 在取消失败的任务时被杀死
- mysql - MySQL DELETE 语句在大表中非常慢
- android - 使用 ViewModel 同时更新所有片段数据
- python - PyGame 绘制一个空白窗口直到退出
- python - Python raspberry pi - 如何将 RAM 内存视为文件
- xamarin.forms - Xamarin 表单 - 网格上的 IsClipedToBounds 不起作用。子视图仍在裁剪
- apache-nifi - NIFI PutHDFS 无法写入内容
- oauth-2.0 - 谷歌开放ID连接