我有以下表结构:
ADVERTITEMBUY | ADVERTITEMSELL
Id (PK) | Id (PK)
Title | Title
... | ...
-------------------------------------
BIDITEMBUY | BIDITEMSELL
AdvertItemBuy (PK/FK) | AdvertItemSell (PK/FK)
... | ...
以编程方式,我正在做这个类结构:
public abstract class Advert : BaseEntity {
public Guid Id { get; set; }
public string Title { get; set; }
...
}
public class AdvertItemBuy : Advert {
...
}
public class AdvertItemSell : Advert {
...
}
-------------------------------------------------------------
public abstract class Bid : BaseEntity {
public Advert Advert { get; set; }
...
}
public class BidItemBuy : Bid {
...
}
public class BidItemSell : Bid {
...
}
当我去Fluent NHibernate绘制这些课程时,我是这样做的:
public class BaseMapping<T> : ClassMap<T> where T : BaseEntity {
public BaseMapping(string table, bool cacheEntities = false) {
Schema("dbo");
Table(string.Format("[{0}]", table));
if (cacheEntities) {
Cache.ReadWrite();
}
}
}
public class AdvertMapping<T> : BaseMapping<T> where T : Advert {
public AdvertMapping(string tableName) : base(tableName) {
Id(advert => advert.Id).GeneratedBy.Guid();
}
}
public class AdvertItemBuyMapping: AdvertMapping<AdvertItemBuy> {
public AdvertItemBuyMapping() : base("AdvertItemBuy") { }
}
public class BidMapping<T> : BaseMapping<T> where T : Bid {
public BidMapping(string tableName, string advertTable) : base(tableName) {
CompositeKey()
.KeyReference(bid => bid.Advert, advertTable);
}
}
public class BidItemBuyMapping : BidMapping<BidItemBuy> {
public BidItemBuyMapping() : base("BidItemBuy", "AdvertItemBuy") { }
}
好的,我认为映射是正确的。当我尝试创建一个新的会话工厂时,NHibernate给了我以下错误:
{"An association from the table [BidItemBuy] refers to an unmapped class: SYB.Engine.Entities.Advert"}
我在这方面做错了什么?
谢谢大家!