NHibernate QueryOver Multiple Order By 与别名
这是我的情况:
public IEnumerable<ISuperMerc> getSuperMercTree(string IDLanguage)
{
SuperMercModel SMer = null;
SuperMercDescriptionModel descrSMer = null;
MercModel Merc = null;
MercDescriptionModel descrMerc = null;
var qOver = _HibSession.QueryOver<SuperMercModel>(() => SMer)
.JoinAlias(() => SMer.DescriptionsSM, () => descrSMer,JoinType.LeftOuterJoin)
.Where(() => descrSMer.IDLanguage == IDLanguage)
.JoinAlias(() => SMer.Merc, () => Merc,JoinType.LeftOuterJoin)
.JoinAlias(() => Merc.DescriptionsMer, () => descrMerc,JoinType.LeftOuterJoin)
.Where(() => descrMerc.IDLanguage == IDLanguage)
.OrderByAlias(() => SMer.ID).Asc
.ThenByAlias(() => descrMerc.Description).Asc
.Future<SuperMercModel>();
return qOver;
}
我遇到了以下错误
无法解析属性:描述:SuperMercModel
奇怪的是,描述字段位于 MercDescriptionModel 类中,而不是 SuperMercModel 类中。
我正在使用别名创建多重联接和多重排序查询。
This is my scenario:
public IEnumerable<ISuperMerc> getSuperMercTree(string IDLanguage)
{
SuperMercModel SMer = null;
SuperMercDescriptionModel descrSMer = null;
MercModel Merc = null;
MercDescriptionModel descrMerc = null;
var qOver = _HibSession.QueryOver<SuperMercModel>(() => SMer)
.JoinAlias(() => SMer.DescriptionsSM, () => descrSMer,JoinType.LeftOuterJoin)
.Where(() => descrSMer.IDLanguage == IDLanguage)
.JoinAlias(() => SMer.Merc, () => Merc,JoinType.LeftOuterJoin)
.JoinAlias(() => Merc.DescriptionsMer, () => descrMerc,JoinType.LeftOuterJoin)
.Where(() => descrMerc.IDLanguage == IDLanguage)
.OrderByAlias(() => SMer.ID).Asc
.ThenByAlias(() => descrMerc.Description).Asc
.Future<SuperMercModel>();
return qOver;
}
I've encountered the following error
could not resolve property: Description of: SuperMercModel
It's strange, the Description field is in the MercDescriptionModel class not in the SuperMercModel class.
I'm using aliases to create a multiple-join and multiple-order-by query.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果将
OrderByAlias
和ThenByAlias
更改为常规OrderBy
和ThenBy
子句,您的原始代码应该无需使用 SQL 即可工作。我遇到了同样的问题,这为我解决了。Your original code should work without using SQL if you change your
OrderByAlias
andThenByAlias
to regularOrderBy
andThenBy
clauses. I had this same issue and that resolved it for me.我已经使用 HQL 解决了这个问题
代码。
这是我希望对某人有帮助的
I've solved it using HQL
Here the code
I hope it's helpful for someone.