猿问

Linq NHibernate 查询子项

我需要获取一些信息,但我是 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();

}

我怎样才能获得邻里信息?


湖上湖
浏览 218回答 1
1回答

天涯尽头无女友

我找到了答案,在查询中,需要这样:using(var session = openSession()){&nbsp; &nbsp; var q = session.Query<Person>(a => Id == IdSearch)&nbsp; &nbsp; &nbsp; &nbsp;.Fetch(a => a.Address)&nbsp; &nbsp; &nbsp; &nbsp;.ThenFetch(a => a.City)&nbsp; &nbsp; &nbsp; &nbsp;.Fetch(a => a.Address)//search address again to have access to neighboorhoor&nbsp; &nbsp; &nbsp; &nbsp;.ThenFetch(a => a.Neighborhood)&nbsp; &nbsp; &nbsp; &nbsp;.ToList();&nbsp; &nbsp; session.Clear();}
随时随地看视频慕课网APP
我要回答