0
我正在爲學校做一個NHibernate演示,但我遇到了一個我無法解決的問題。 你有一張票和票務回覆。硬件標籤繼承票證。 當執行ReadTicket方法,我收到了WrongclassException說Nhibernate映射鑑別器「錯誤的類例外」
「對象沒有指定的子類:SC.BL.Domain.Ticket (鑑別是:」)」
如果有人能幫助我,我會很高興
public class Ticket
{
public virtual int AccountId { get; set; }
public virtual DateTime DateOpened { get; set; }
[Required]
[MaxLength(100, ErrorMessage = "Er zijn maximaal 100 tekens toegestaan")]
public virtual string Text { get; set; }
public virtual int TicketNumber { get; set; }
public virtual TicketState State { get; set; }
public virtual IList<TicketResponse> Responses { get; set; }
}
public class HardwareTicket : Ticket
{
[RegularExpression("^(PC-)[0-9]+")]
public virtual string DeviceName { get; set; }
}
庫:
public class TicketRepository : ITicketRepository
{ private static ISessionFactory mySessionFactory;
Private static ISession mySession;
public TicketRepository()
{
if (mySessionFactory == null)
{
var configuration = new Configuration().Configure("hibernate.cfg.xml");
configuration.AddAssembly(typeof(Ticket).Assembly);
configuration.AddAssembly(typeof(TicketResponse).Assembly);
mySessionFactory = configuration.BuildSessionFactory();
}
}
public Ticket ReadTicket(int ticketNumber)
{
using (mySession = mySessionFactory.OpenSession())
{
var ticket = mySession.QueryOver<Ticket>().Where(x => x.TicketNumber == ticketNumber).SingleOrDefault();
return ticket;
}
}
映射:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="SC.BL.Domain"
namespace ="SC.BL.Domain">
<class name="Ticket" table="Ticket" lazy ="true">
<id name="TicketNumber">
<generator class="identity"> </generator>
</id>
<discriminator column="Discriminator" type="System.String" not-null="true"/>
<property name="AccountId"></property>
<property name="Text"></property>
<property name="DateOpened"></property>
<property name="State"></property>
<bag name="Responses" lazy="true" inverse="true"
batch-size="25" cascade="all-delete-orphan">
<key column="TicketNumber" />
<one-to-many class="TicketResponse" />
</bag>
<subclass name="HardwareTicket" discriminator-value ="HardwareTicket" >
<property name="DeviceName" not-null="false"></property>
</subclass>
<subclass name="Ticket" discriminator-value ="Ticket" >
</subclass>
</class>
</hibernate-mapping>