如何在Nhibernate中加入两个表

List olist = null; olist = (_session.CreateQuery("Select pc.Id as Id,pct.DescEn as DescEn,pct.DescAr as DescAr,pc.ContentEn as ContentEn,pc.ContentAr as ContentAr from ProjectCharter pc,ProjectCharterTemplate pct where pct.Id=pc.PRC_PCT_ID and pc.PRC_PRJ_ID=1").List()).ToList(); 

这是我的查询,我想加入两个表并得到一个输出,当我运行这是db我得到完美的回答,但当我通过c#与nhibernate映射运行它。 我得到错误。

我可以这样查询,还是有任何其他方法来连接两个表。

提前致谢。

这很简单。 非常容易。 检查

  • 15.标准查询或
  • 16. QueryOver查询 API。

所以,QueryOver中的上述查询可能如下所示:

 // alias for later use ProjectCharter project = null; ProjectCharterTemplate template = null; var list = session .QueryOver(() => project) // the JOIN will replace the WHERE in the CROSS JOIN above // it will be injected by NHibernate based on the mapping // relation project has many-to-one template .JoinQueryOver(c => c.Templates, () => template) .Select( // select some project properties _ => project.ContentEnglish, ... // select some template properties _ => template.DescriptionEnglish, ) .List();