“表未映射”与 NHibernate +活动记录

发布于 08-15 22:08 字数 625 浏览 7 评论 0原文

我正在使用 Active Record 和 ActiveRecord Facility,并尝试使用自定义 NHibernate 查询。即使类扩展了 ActiveRecordBase 并具有 ActiveRecord 属性,我是否需要为该类定义映射?

[ActiveRecord("VotesOnQuestions")]
public class VoteOnQuestion : ActiveRecordBase<VoteOnQuestion>
{
    [CompositeKey]
    public VoteKey Key { get; set; }

    [Property]
    public VoteType Vote { get; set; }
}

我正在尝试创建以下查询:

session.CreateQuery("SELECT vote, COUNT(*) FROM votesonquestions" +
                    " WHERE questionid = :questionId GROUP BY vote");

但我收到此异常:

“投票问题未映射”

I'm using Active Record with ActiveRecord Facility, and am trying to use a custom NHibernate query. Do I need to define a mapping for a class even though it extends ActiveRecordBase and has ActiveRecord attribute?

[ActiveRecord("VotesOnQuestions")]
public class VoteOnQuestion : ActiveRecordBase<VoteOnQuestion>
{
    [CompositeKey]
    public VoteKey Key { get; set; }

    [Property]
    public VoteType Vote { get; set; }
}

I'm trying to create the following query:

session.CreateQuery("SELECT vote, COUNT(*) FROM votesonquestions" +
                    " WHERE questionid = :questionId GROUP BY vote");

But I'm getting this exception:

"votesonquestions is not mapped"

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

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

发布评论

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

评论(1

你没皮卡萌2024-08-22 22:08:34

正如例外情况所示,您需要一个标有 [ActiveRecord] 的类来映射 votesonquestions (我猜它是这样调用的)表。

ActiveRecordBase 继承是可选的。

在查询中,您只能引用映射的类(区分大小写),而不能引用表。所以在这种情况下,查询应该是:

session.CreateQuery("SELECT vote, COUNT(*) FROM VoteOnQuestion" +
                    " WHERE questionid = :questionId GROUP BY vote");

Just as the exception says, you need a class marked with [ActiveRecord] that maps the votesonquestions (I'm guessing it's called like that) table.

Inheriting from ActiveRecordBase is optional.

In the query you can only refer mapped classes (which are case-sensitive), not tables. So in this case, the query should be:

session.CreateQuery("SELECT vote, COUNT(*) FROM VoteOnQuestion" +
                    " WHERE questionid = :questionId GROUP BY vote");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文