我需要获取一些信息,但是我是NHibernate的新手
我有类似的课程:
Person
Id
IdAddress
Address
Address
Id
IdCity
City
IdNeighborhood
Neighborhood
和课程
City
Neighborhood
我需要所有带有邻居ID的地址, 这段代码是我搜索信息的地方,但是这里只显示城市:
using(var session = openSession()){
var q = session.Query<Person>(a => Id == IdSearch)
.Fetch(a => a.Address)
.ThenFetch(a => a.City)
.ToList();
session.Clear();
}
我还如何获得邻居信息?
答案 0 :(得分:1)
我找到了答案, 在查询中,需要这样:
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();
}