我想出了我的問題。這裏是我的代碼:
public abstract class Event : Entity
{
protected Event() { }
public Event(string name, DateTime startDate)
{
this.Name = name;
this.StartDate = startDate;
}
public virtual string Name { get; private set; }
public virtual string Description { get; set; }
public virtual DateTime StartDate { get; protected set; }
public virtual DateTime? EndDate { get; set; }
}
public class SpecialEvent : Event
{
protected SpecialEvent() { }
public SpecialEvent(DateTime startDate, string name) : base(name, startDate) { }
}
public class RecurringEvent : Event
{
protected RecurringEvent() { }
public RecurringEvent(string name, DateTime startDate, DateTime baseDate, int recurrenceIntervalDays)
: base(name, startDate)
{
this.RecurrenceIntervalDays = recurrenceIntervalDays;
this.BaseDate = baseDate;
}
public virtual int RecurrenceIntervalDays { get; protected set; }
public virtual DateTime BaseDate { get; protected set; }
}
public class EventMap : EntityMap<Event>
{
public EventMap()
{
Map(x => x.Name);
Map(x => x.Description);
Map(x => x.StartDate);
Map(x => x.EndDate);
}
}
public class SpecialEventMap : SubclassMap<SpecialEvent>
{
public SpecialEventMap()
{
KeyColumn("Id");
}
}
public class RecurringEventMap : SubclassMap<RecurringEvent>
{
public RecurringEventMap()
{
KeyColumn("Id");
Map(x => x.BaseDate);
Map(x => x.RecurrenceIntervalDays);
}
}