如何在Nhibernate中联接两个表

Hud*_*suf 4 c# nhibernate inner-join

List<object[]> 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<object[]>()).ToList<object[]>();
Run Code Online (Sandbox Code Playgroud)

这是我的查询,我想联接两个表并获得输出,当我运行这是数据库时,我得到了完美的答案,但是当我通过带有nhibernate映射的c#运行它时。我得到错误。

我可以用这种方式查询还是有其他方法来联接两个表。

提前致谢。

Rad*_*ler 5

这很容易。出奇的容易。检查

因此,上面的QueryOver查询看起来可能像这样:

// alias for later use
ProjectCharter project = null;
ProjectCharterTemplate template = null;

var list = session
    .QueryOver<ProjectCharter>(() => 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<ProjectCharterTemplate>(c => c.Templates, () => template)
    .Select(
        // select some project properties
        _ => project.ContentEnglish,
        ...
        // select some template properties
        _ => template.DescriptionEnglish,
     )
    .List<object[]>();
Run Code Online (Sandbox Code Playgroud)