NPoco - include with IncludeMany with other include (ASP NET MVC)

524 views Asked by At

hi i need to get a record, which is related to 3 tables:

Routes -> one to one -> StartCity & EndCity

Routes -> one to many -> StopoverCity -> one to one -> City

** Sorry for my bad english

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;
}
1

There are 1 answers

0
LeviatanMX On

Solved..!

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