NHibernate QueryOver Multiple Order By 与别名

发布于 2024-12-13 22:34:00 字数 1184 浏览 2 评论 0原文

这是我的情况:

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无悔心 2024-12-20 22:34:00

如果将 OrderByAliasThenByAlias 更改为常规 OrderByThenBy 子句,您的原始代码应该无需使用 SQL 即可工作。我遇到了同样的问题,这为我解决了。

Your original code should work without using SQL if you change your OrderByAlias and ThenByAlias to regular OrderBy and ThenBy clauses. I had this same issue and that resolved it for me.

挽容 2024-12-20 22:34:00

我已经使用 HQL 解决了这个问题
代码。

public IEnumerable<ISuperMerc> getSuperMercTree(string IDLanguage)
{
    string hql = string.Empty;

     hql = "select SM from SuperMercModel SM"
                + " left join fetch SM.DescriptionsSM DSM"
                + " left join fetch SM.Merc ME"
                + " left join fetch ME.DescriptionsMer DME"
                + " where DSM.IDLanguage = :IDLanguage "
                + " and DME.IDLanguage = :IDLanguage "
                + " order by SM.ID asc, DME.Description asc";

            IQuery query = _HibSession
                .CreateQuery(hql)
                .SetString("IDLanguage ", IDLanguage );

            IList<SuperMercModel> result = query.List<SuperMercModel>();


            return result;
}

这是我希望对某人有帮助的

I've solved it using HQL
Here the code

public IEnumerable<ISuperMerc> getSuperMercTree(string IDLanguage)
{
    string hql = string.Empty;

     hql = "select SM from SuperMercModel SM"
                + " left join fetch SM.DescriptionsSM DSM"
                + " left join fetch SM.Merc ME"
                + " left join fetch ME.DescriptionsMer DME"
                + " where DSM.IDLanguage = :IDLanguage "
                + " and DME.IDLanguage = :IDLanguage "
                + " order by SM.ID asc, DME.Description asc";

            IQuery query = _HibSession
                .CreateQuery(hql)
                .SetString("IDLanguage ", IDLanguage );

            IList<SuperMercModel> result = query.List<SuperMercModel>();


            return result;
}

I hope it's helpful for someone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文