首页 > 解决方案 > 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;
}

标签: c#asp.net-mvcnpoco

解决方案


解决了..!

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

推荐阅读