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.
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 ...
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? 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.
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'.
You need to go the .hbm.xml file > properties > Build Action set to Embedded Resource
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With