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[]>();
这是我的查询,我想联接两个表并获得输出,当我运行这是数据库时,我得到了完美的答案,
但是当我通过带有nhibernate映射的C#运行它时。我得到错误。
我可以用这种方式查询还是有其他任何方法来联接两个表。
提前致谢。
最佳答案
这很简单。出奇的容易。检查
因此,上面的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[]>();
关于c# - 如何在Nhibernate中联接两个表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28738893/