2010-01-06 19 views
8

Bu NHibernate sorunuyla saatlerce uğraşıyorum. Web'de ve NHibernate belgelerinde kapsamlı bir araştırma yaptım ve bu konu hakkında hiçbir fikrim yok. NHibernate için nispeten yeni ve seviyorum. Bu durumda, yine de beni delirtiyor.C#/NHibernate: İlişkilendirilmemiş başvurular sınıflanmamış

Web sitesi için küçük bir "Anket" modülü yazıyorum. Birkaç dersim var (Poll, PollVote ve PollAnswer). Ana, Poll, soruna neden olan. Bu, bu sınıf göründüğünü gibi:

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

Ve böyle haritalama görünür:

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

Gerçekten bu anlamak istiyorum: Bu bana hata verir

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

ve NHibernate'in iç işleyişini daha iyi anlar. PollAnswer "sınıfını" göremediğini anlamıyorum.

cevap

8

Poll ve PollAnswer arasında bire çok ilişki tanımlarsınız.Bu nedenle, hbm.xml dosyanızda PollAnswer için bir bölüme ihtiyacınız olacaktır. . Sen PollVote için bir tane de gerekir.

+13

Ayrıca Embedded kaynak olarak ayarlanmış Eylem kurmak, Eylem oluşturmak sağlamak Gömülü Kaynak olarak ayarlandı – bitsprint

12

Sen> .hbm.xml dosyasını gitmek özelliklerini ihtiyaç> hbm.xml dosya özelliklerinde

İlgili konular