我正在使用nhibernate在MVC3中开发一个应用程序来触发数据库查询。
我有两个模特。 HobbyMasters HObbyDetail
HobbyMaster类包含:
HobbyId
and other details
HobbyDetail Class包含:
HobbyDetaild
HobbyMasters hobbymaster
other detals
现在我想使用Icrteria在两个表之间执行jon:
ICriteria criteria = session.CreateCriteria<HobbyDetail>()
.CreateAlias("HobbyMasters", "HobbyMasters")
.Add(Restrictions.EqProperty("HobbyMasters.HobbyId", "HobbyDetail.hobbymaster.HobbyId"));
还有:
HobbyDetail = session.CreateCriteria(typeof(HobbyDetail))
.CreateAlias("HobbyMasters", "HobbyMasters", NHibernate.SqlCommand.JoinType.InnerJoin)
.Add(Restrictions.EqProperty("HobbyMasters.hobbymaster.HobbyId", "HobbyDetail.HobbyId"))
但是我得到一个错误,说无法解决HobbyDetail Class的属性HobbyMaster
请帮帮我
答案 0 :(得分:0)
您可以使用QueryOver,它是使用Lambda表达式的ICriteria的包装器:
session.QueryOver<HobbyDetail>()
.Fetch(hobbyDetail => hobbyDetail.HobbyMasters).Eager
.TransformUsing(Transformers.DistinctRootEntity)
.List();