我正在尝试使用 NHibernate 创建查询并沿多个外键搜索:
当我只搜索一个外键时,以下代码有效:
ICriteria query = Session.CreateCriteria<TblTeam>()
.Add<TblTeam>(x => x.FldUrlSafeName == teamName)
.CreateCriteria<TblTeam>(x => x.TblSportsType)
.Add<TblSportsType>(x => x.FldUrlSafeName == sportsType);
return query.UniqueResult<TblTeam>();
我需要搜索两个外键,所以我创建了以下内容:
ICriteria query = Session.CreateCriteria<TblTeam>()
.Add<TblTeam>(x => x.FldUrlSafeName == teamName)
.CreateCriteria<TblTeam>(x => x.TblSportsType)
.Add<TblSportsType>(x => x.FldUrlSafeName == sportsType)
.CreateCriteria<TblTeam>(x => x.TblSportsOrganization)
.Add<TblSportsOrganization>(x => x.FldUrlSafeName == sportsOrganization);
return query.UniqueResult<TblTeam>();
不幸的是,这给了我以下错误:
“无法解析属性:TblSportsOrganization of:site.Core.TblSportsType”
我将如何让它“退后一步”,以便我可以将标准添加到 TblTeam 而不是 TblSportsType?