“表未映射”与 NHibernate +活动记录
我正在使用 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 技术交流群。

正如例外情况所示,您需要一个标有
[ActiveRecord]
的类来映射 votesonquestions (我猜它是这样调用的)表。从
ActiveRecordBase
继承是可选的。在查询中,您只能引用映射的类(区分大小写),而不能引用表。所以在这种情况下,查询应该是:
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: