NPoco - включить с IncludeMany с другим include (ASP NET MVC) - PullRequest
0 голосов
/ 13 июня 2019

Привет мне нужно получить запись, которая связана с 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;
}

1 Ответ

0 голосов
/ 18 июня 2019

решаемые ..!

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