本文介绍了如何在Nhibernate中联接两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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#运行它时.我收到错误消息.
This is My Query, I want to join two tables and get an output,when i run this is the db i get the perfect answere,but when i run it through c# with nhibernate mapping. i get errors.
我可以用这种方式查询还是有其他方法可以联接两个表.
Can i query this way or is there any other method to join two tables.
提前谢谢.
推荐答案
这很容易.出奇的容易.检查
This is easy. Suprisingly easy. Check the
- 15.条件查询或
- 16. QueryOver Queries API.
- 15. Criteria Queries or
- 16. QueryOver Queries API.
因此,上面的QueryOver查询看起来可能像这样:
So, the above query in QueryOver could look like this:
// 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[]>();
这篇关于如何在Nhibernate中联接两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!