【问题标题】:NPoco - include with IncludeMany with other include (ASP NET MVC)NPoco - 包含 IncludeMany 和其他包含 (ASP NET MVC)
【发布时间】:2019-06-13 17:28:48
【问题描述】:

您好,我需要获取与 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;
}

【问题讨论】:

    标签: c# asp.net-mvc npoco


    【解决方案1】:

    解决了..!

    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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-09
      • 2013-04-18
      • 2019-01-30
      • 2012-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多