2010-01-06 11 views
8

Mam problem z tym NHibernate problem godzinami. Dogłębnie analizowałem w sieci oraz dokumentację NHibernate i nie mogę zrozumieć tego problemu. Jestem względnie nowy w NHibernate i bardzo mi się podoba. W takim razie doprowadza mnie to do szału.C#/NHibernate: Odwołania asocjacji niezmapowanej klasy

Piszę mały moduł "Ankieta" dla strony internetowej. Mam kilka klas (Ankieta, PollVote i PollAnswer). Główny problem, sondaż, jest przyczyną problemu. To ten, co wygląda klasa jak:

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; } 
    } 

I to mapowanie wygląda następująco:

<?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> 

to zwraca mi błąd:

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

Naprawdę chcesz to zrozumieć i lepiej zrozumieć wewnętrzne działanie NHibernate. Nie rozumiem, jak nie można "zobaczyć" klasy PollAnswer "

Odpowiedz

8

Definiujesz jeden do wielu relacji między sondą i PollAnswer, dlatego potrzebujesz sekcji dla PollAnswer w pliku hbm.xml . Musisz po jednym dla PollVote również.

+13

Dodatkowo we właściwościach plików hbm.xml, zapewnienie akcji Zbuduj jest ustawiony na Embedded Resource – bitsprint

12

Musisz iść plik .hbm.xml> właściwości> Budowanie akcji osadzona na Embedded Resource

Powiązane problemy