我正在使用 nhibernate 在 MVC3 中开发一个应用程序我有两个表,我想在两者之间执行连接,并且我还想包含多个 where 条件。我发布了所有相关的表,以便清除要求:
First table is HobbyMaster:
HobbyId
HobbyName
Second Table is HobbyHome:
HobbyHomeId
HobbyHomeName
Third Table is HobbyDetail:
HobbyDetailId
HobbyId(Foreign Key)
HobbyHomeId(Foreign key)
Fourth Table is HobbyHomeAddress:
Id(primary key)
HobbyHomeId(Foreign key)
StateId(Foreign Key)
DistrictId(Foreign key)
Fifth Table is State:
stateid
statename
last Table is District:
districtid
districtname
我想写一个这样的查询:
select * from HobbyHomeAddress hobadd,
HobbyDetail hobdet
where hobdet.HobbyId=hobbyid
and hobadd.HobbyId=hobdet.HobbyId
and hobadd.StateId=stateid;
我试过了,但它不工作,也给了我 NUll
hobbyhomeaddress = session.CreateCriteria(typeof(HobbyHomeAddress))
.CreateAlias("HobbyDetail", "HobbyDetail", NHibernate.SqlCommand.JoinType.InnerJoin)
.Add(Expression.Eq("HobbyID", hobbyid))
.Add(Restrictions.Eq("HobbyHomeAddress.HobbyHomeId", "HobbyDetail.HobbyHomeId"))
.Add(Expression.Eq("ProvincialState.ProvincialStateID", stateid))
.List<HobbyHomeAddress>();
我可以通过 ajax 获取 id,但我不明白如何触发以下查询请帮助我