Lucas Prestes
Lucas Prestes

Reputation: 402

Linq NHibernate Query Subitems

I need to get some informations, but I am new in NHibernate

I have classes like:

Person
   Id
   IdAddress
   Address

Address
   Id
   IdCity
   City
   IdNeighborhood
   Neighborhood

and classes

City
Neighborhood

I need all address with a neighboorhood id, This code is where I search the information, but here only get the city:

using(var session = openSession()){
   var q = session.Query<Person>(a => Id == IdSearch)
           .Fetch(a => a.Address)
           .ThenFetch(a => a.City)
           .ToList();
   session.Clear();
}

How could I also get neighboorhood information?

Upvotes: 2

Views: 73

Answers (1)

Lucas Prestes
Lucas Prestes

Reputation: 402

I find the answer, In the query, need to be in this way:

using(var session = openSession()){
    var q = session.Query<Person>(a => Id == IdSearch)
       .Fetch(a => a.Address)
       .ThenFetch(a => a.City)
       .Fetch(a => a.Address)//search address again to have access to neighboorhoor
       .ThenFetch(a => a.Neighborhood)
       .ToList();
    session.Clear();
}

Upvotes: 1

Related Questions