Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#/NHibernate: Association references unmapped class

Tags:

c#

nhibernate

I have been struggling with this NHibernate issue for hours. I extensively researched on the web as well as the NHibernate documentation, and I can make no sense of this issue. I'm relatively new to NHibernate, and love it. In that case, though, it's driving me mad.

I'm writing a small "Poll" module for a website. I have several classes (Poll, PollVote and PollAnswer). The main one, Poll, is the one causing the issue. This this what the class looks like:

public class Poll
    {
        public virtual int Id { get; set; }
        public virtual Site Site { get; set; }
        public virtual string Question { get; set; }
        public virtual bool Locked { get; set; }
        public virtual bool Enabled { get; set; }
        public virtual ICollection<PollAnswer> AnswersSet { get; set; }
        public virtual ICollection<PollVote> VotesSet { get; set; }
    }

And this is what the mapping looks like:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="Folke"
                   namespace="Folke.Code.Domain">
  <class name="Poll">
    <id name="Id">
      <generator class="native"></generator>
    </id>
    <property name="Site"/>
    <property name="Question"/>
    <property name="Locked"/>
    <property name="Enabled"/>
    <set name="AnswersSet" lazy="true">
      <key column="PollId"/>
      <one-to-many class="PollAnswer"/>
    </set>
    <set name="VotesSet" lazy="true">
      <key column="PollId"/>
      <one-to-many class="PollVote"/>
    </set>
  </class>
</hibernate-mapping>

This returns me an error:

Association references unmapped class: Folke.Code.Domain.PollAnswer Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: NHibernate.MappingException: Association references unmapped class: Folke.Code.Domain.PollAnswer

I really want to understand this, and understand better the inner working of NHibernate. I don't understand how it cannot "see" the PollAnswer" class.

like image 829
Astaar Avatar asked Jan 06 '10 20:01

Astaar


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is C full form?

Full form of C is “COMPILE”. One thing which was missing in C language was further added to C++ that is 'the concept of CLASSES'.


2 Answers

You need to go the .hbm.xml file > properties > Build Action set to Embedded Resource

like image 114
HPP Avatar answered Oct 20 '22 01:10

HPP


You're defining a one to many relationship between Poll and PollAnswer. Therefore, you'll need a section for PollAnswer in your hbm.xml file. You'll need one for PollVote as well.

like image 21
anthony Avatar answered Oct 20 '22 02:10

anthony