nhibernate 分页 列“...”为“查询”指定了多次;

发布于 2024-11-18 14:48:37 字数 1427 浏览 2 评论 0原文

使用分页进行查询时出现错误“为“查询”指定了多次“Translat2_”列”。

我的类层次结构:

Politician
--PoliticianInFactions : PoliticianInFaction
--EntityTranslations : Translation

Faction
--PoliticiansInFaction : PoliticianInFaction
--EntityTranslations : Translation

Translation
--Name : String
--Language : Language

我想要的:获取按其派系名称排序的政客,而不是按其名称排序。 我的查询:

var criteria = Session.CreateCriteria<Politician>("politician");

// criteria for current faction
var currentFactionCriteria = criteria
    .CreateCriteria<Politician>(x => x.PoliticianInFactions, JoinType.InnerJoin)
    .Add<PoliticianInFaction>(x => x.FromDate <= DateTime.Now)
    .CreateCriteria<PoliticianInFaction>(x => x.Faction, JoinType.InnerJoin);

// add order by faction's name !!!
currentFactionCriteria
    .CreateCriteria<Faction>(x => x.EntityTranslations, JoinType.InnerJoin)
    .Add<Translation>(x => x.Language.Id == languageId)
    .AddOrder<CityTranslation>(x => x.Name, Order.Asc);

// add order by politician's name !!!
criteria
    .CreateCriteria<Politician>(x => x.EntityTranslations, JoinType.InnerJoin)
    .Add<Translation>(x => x.Language.Id == languageId)
    .AddOrder<Translation>(x => x.Name, Order.Asc);  

向此查询添加分页时出现错误。无需分页一切正常。另外,如果我评论(删除)任何标有(!!!)异常的块就会消失。 我做错了什么?如果这是 NHibernate 的错误,请给我一些解决方法。谢谢。

I have an error "The column 'Translat2_' was specified multiple times for 'query'" when using paging for my query.

My classes hierarchy:

Politician
--PoliticianInFactions : PoliticianInFaction
--EntityTranslations : Translation

Faction
--PoliticiansInFaction : PoliticianInFaction
--EntityTranslations : Translation

Translation
--Name : String
--Language : Language

What I want: to fetch politicians ordered by its faction's name and than by its name.
My query:

var criteria = Session.CreateCriteria<Politician>("politician");

// criteria for current faction
var currentFactionCriteria = criteria
    .CreateCriteria<Politician>(x => x.PoliticianInFactions, JoinType.InnerJoin)
    .Add<PoliticianInFaction>(x => x.FromDate <= DateTime.Now)
    .CreateCriteria<PoliticianInFaction>(x => x.Faction, JoinType.InnerJoin);

// add order by faction's name !!!
currentFactionCriteria
    .CreateCriteria<Faction>(x => x.EntityTranslations, JoinType.InnerJoin)
    .Add<Translation>(x => x.Language.Id == languageId)
    .AddOrder<CityTranslation>(x => x.Name, Order.Asc);

// add order by politician's name !!!
criteria
    .CreateCriteria<Politician>(x => x.EntityTranslations, JoinType.InnerJoin)
    .Add<Translation>(x => x.Language.Id == languageId)
    .AddOrder<Translation>(x => x.Name, Order.Asc);  

When adding paging to this query I have an error. Without paging everything is OK. Also if I comment(remove) any block marked with (!!!) exception dissapears.
What am I doing wrong? If this is a bug of NHibernate give me some workaround please. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

演出会有结束 2024-11-25 14:48:37

检查映射文件以查看是否已将多个属性映射到同一数据库列或将同一数据库列映射到多个属性。

Check you mapping files to see if you have mapped multiple properties to the same database column or mapped the same databases column to multiple properties.

淡笑忘祈一世凡恋 2024-11-25 14:48:37

我知道这是一个古老的话题,但这个问题最近困扰着我。

我发现映射中属性调用的大小写与分页相关。即,如果您有一个属性,其中包含名为“field”的列,并且您也将其映射到另一个属性,那么如果 field 的大小写相同,这将不是问题。

但是,如果您使用名为“Field”的列来标识其他映射,分页将不知道这不是一个不同的属性,并将尝试查询同一列两次!

I know that this is an ancient thread, but this issue plagued me recently.

I've discovered that the case of the property calls in your mapping matters relative to paging. I.E. if you have a property with a column called "field" and you map it to another property as well, this will not be an issue if the case of field is the same.

However, if you identify your other mapping with a column called "Field", paging will not know that this is not a distinct property and will try to query the same column twice!

梦里梦着梦中梦 2024-11-25 14:48:37

我猜您遇到了 CASE 或重复问题。在我的问题中,我遇到以下情况:

在此处输入图像描述

我以不同的方式两次使用“serie id”列..我将“S”放入较低且在上..我希望有帮助..

I guess that you have a CASE or duplicate problem.In my issue I have the following situation:

enter image description here

I take the column "serie id" two times but in different ways.. I put "S" in lower and in upper.. I hope that helps..

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