0

我正在使用 nhibernate 在 MVC3 中开发一个应用程序来触发数据库查询。

我有两个模型。爱好大师爱好详情

HobbyMaster 类包含:

HobbyId
and other details

HobbyDetail 类包含:

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 类的属性 HobbyMaster

请帮我

4

1 回答 1

0

You can use QueryOver, it's a wrapper on ICriteria with Lambda Expressions:

session.QueryOver<HobbyDetail>()
  .Fetch(hobbyDetail => hobbyDetail.HobbyMasters).Eager
  .TransformUsing(Transformers.DistinctRootEntity)
  .List();
于 2012-04-23T18:15:48.807 回答