"Table not mapped" with NHibernate + Active Record
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<Vote开发者_Python百科OnQuestion>
{
[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"
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");
精彩评论