C# 如何在Nhibernate中连接两个表

C# 如何在Nhibernate中连接两个表,c#,nhibernate,inner-join,C#,Nhibernate,Inner Join,这是我的查询,我想连接两个表并得到一个输出, 当我运行这个数据库时,我得到了完美的答案, 但是当我用nhibernate映射通过c运行它时。我会犯错误 我可以这样查询,还是有其他方法连接两个表 提前谢谢。这很容易。令人惊讶的简单。检查 或 应用程序编程接口。 因此,QueryOver中的上述查询可能如下所示: List<object[]> olist = null; olist = (_session.CreateQuery("Select pc.Id as Id, &q

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

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


提前谢谢。

这很容易。令人惊讶的简单。检查

或 应用程序编程接口。 因此,QueryOver中的上述查询可能如下所示:

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[]>();

当您使用纯SQL时,您希望使用ADO.NET而不是nHibernate。nHibernate是指您不想自己编写SQL的时候。@Euphoric是的,我能够运行IQuery并将其转换为列表。这就是答案
// 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[]>();