gpt4 book ai didi

c# - Linq NHibernate 查询子项

转载 作者:太空宇宙 更新时间:2023-11-03 12:12:22 25 4
gpt4 key购买 nike

我需要获取一些信息,但我是 NHibernate 的新手

我有这样的类(class):

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

我怎样才能获得社区信息?

最佳答案

我找到了答案,在查询中,需要这样:

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

关于c# - Linq NHibernate 查询子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51499928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com