c# - NPoco - 包含 IncludeMany 和其他包含 (ASP NET MVC)
问题描述
嗨,我需要获取与 3 个表相关的记录:
路线 -> 一对一 -> StartCity & EndCity
路线 -> 一对多 -> StopoverCity -> 一对一 -> 城市
** 对不起,我的英语不好
public static Route GetById(int id)
{
var result = new Route();
try
{
using (IDatabase db = DBContext.GetInstance())
{
result = db.Query<Route>().Include(x => x.StartCity).Include(x => x.EndCity)
.IncludeMany(x => x.StopoverCity).Where(x => x.Id == id).SingleOrDefault();
// i need to add other include with the StopoverCity
}
}
catch (Exception ex)
{
throw;
}
return result;
}
解决方案
解决了..!
result = db.Query<Route>().Include(x => x.StartCity).Include(x => x.EndCity)
.Where(x => x.Id == id).SingleOrDefault();
// For Route Details
result.StopoverCity= db.Query<StopoverCity>().Include(x => x.City).Where(x => x.IdRoute == id).ToList();
推荐阅读
- python - 在 anaconda 中克隆基础环境
- python - 无法 pip install eel 。- 退出状态为 1 的命令出错:python setup.py egg_info 检查日志以获取完整的命令输出
- ruby - Ruby AWS 开发工具包错误。module_inheritable_attributes.rb 中的值 nil
- excel - 条件格式以突出显示特定单元格但不为空和文本单元格 VBA
- python - 如何从 Map(Type, List) 中删除一个值?
- r - 通过链接shiny和sql来减少负载
- java - java.util.NoSuchElementException:找不到行;每次输入都有一个新变量时出错
- html - React:如何添加唯一的类名?
- sql - 临时表解析 - SQL 错误 - 需要说明
- python - 当我尝试将使用 moviepy 创建的 .mp4 从 PC 导出到 iPhone 时,声音消失了