【问题标题】:Why does my QueryOver<T>().RowCount() throw a NonUniqueResultException?为什么我的 QueryOver<T>().RowCount() 会抛出 NonUniqueResultException?
【发布时间】:2012-12-26 09:02:03
【问题描述】:

我通过为映射到视图的实体指定entity-name 将实体映射到表和视图,如下所示:

到表的映射:

<class name="Foo">

到视图的映射:

<class name="Foo" entity-name="LatestFoo">

然后我尝试在我的控制器中执行此操作:

var latestVersions = Database.QueryOver<Foo>("LatestFoo");
var count = latestVersions.RowCount();

但是对RowCount() 的调用会同时为表和视图运行 SQL 语句:

2012-12-26 13:30:55,700 [31] DEBUG NHibernate.SQL - SELECT count(*) as y0_ FROM LatestFoo this_
2012-12-26 13:30:55,705 [31] DEBUG NHibernate.SQL - SELECT count(*) as y0_ FROM Foo this_

这会导致NonUniqueResultException 带有消息query did not return a unique result: 2

我需要做什么才能让它工作?

【问题讨论】:

    标签: nhibernate queryover


    【解决方案1】:

    您还需要为表的映射指定实体名称。

    看看(滚动到该部分 - 一些陷阱):

    http://nhibernate.info/doc/howto/mapping/mapping-the-same-class-to-a-view-and-a-table-using-entity-name.html

    【讨论】:

    • 准确!感谢您的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多