开发者

"Table not mapped" with NHibernate + Active Record

开发者 https://www.devze.com 2022-12-15 02:06 出处:网络
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 ActiveRec

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");
0

精彩评论

暂无评论...
验证码 换一张
取 消