流利的NHibernate映射复合ID接口

时间:2019-04-12 09:50:50

标签: c# fluent-nhibernate

在现有应用程序中,我尝试使用Fluent NHibernate映射2个新表,其中1个具有复合ID,我无法弄清楚如何正确映射-一切正常,但是我得到了NHibernate MappingException-An association from the table IND_EV_LOCATIONS refers to an unmapped class: IIndEvents当我运行该应用程序时。

我的界面

public interface IIndEvents
{
    long IetEventId { get; set; }
    string IetEventName { get; set; }
    DateTime IetEventDatetime { get; set; }
    DateTime? IetEnddatetime { get; set; }
}

public interface IIndEvLocations
{
    IIndEvents IndEvents { get; set; }
    string IelDispSeq { get; set; }
    DateTime? IelCreatedDate { get; set; }
    string IelCreatedBy { get; set; }
}

我的模型课

public class IndEvents : IIndEvents
{
    public virtual long IetEventId { get; set; }
    public virtual string IetEventName { get; set; }
    public virtual DateTime IetEventDatetime { get; set; }
    public virtual DateTime? IetEnddatetime { get; set; }
}

public class IndEvLocations : IIndEvLocations
{
    public virtual IIndEvents IndEvents { get; set; }
    public virtual string IelDispSeq { get; set; }
    public virtual DateTime? IelCreatedDate { get; set; }
    public virtual string IelCreatedBy { get; set; }
}

我的班级映射

public class IndEventsMap : ClassMap<IndEvents>
{
    public IndEventsMap()
    {
        Table("IND_EVENTS");
        LazyLoad();
        Id(x => x.IetEventId).GeneratedBy.Assigned().Column("EVENT_ID");
        Map(x => x.IetEventName).Column("EVENT_NAME").Not.Nullable().Length(800);
        Map(x => x.IetEventDatetime).Column("EVENT_DATETIME").Not.Nullable().Length(7);
        Map(x => x.IetEnddatetime).Column("ENDDATETIME").Length(7);
    }
}

public class IndEvLocationsMap : ClassMap<IndEvLocations>
{
    public IndEvLocationsMap()
    {
            Table("IND_EV_LOCATIONS");
            LazyLoad();
            CompositeId()
                .KeyReference(x => x.IndEvents, m=> m.ForeignKey("IEL_IET_EVENT_ID"), "IET_EVENT_ID")
                .KeyProperty(x => x.IelDispSeq, x => x.ColumnName("IEL_DISP_SEQ"));
            //References(x => x.IndEvents).Column("IEL_IET_EVENT_ID");
            Map(x => x.IelCreatedDate).Column("IEL_CREATED_DATE").Length(7);
            Map(x => x.IelCreatedBy).Column("IEL_CREATED_BY").Length(128);
    }
}

是否可以将外键的类型设置为实现IIndEvLocations的IndEvLocations,而不是查找IIndEvLocations本身的映射?

0 个答案:

没有答案