2
我有以下表場景:映射外鍵作爲主鍵功能NHibernate
User
- Id (PK)
- Username
Advert
- Id (PK)
- Title
AdvertPhoto
- Advert (PK) (Also a FK for Advert table)
- Image
Bid
- Advert (PK) (Also a FK for Advert table)
- User (PK) (Also a FK for User table)
- Value
好吧,我想這些實體與下面的代碼映射:
public class AdvertMapping : BaseMapping<Advert> {
public AdvertMapping() : base("Advert") {
Id(model => model.Id).Not.Nullable().Unique().GeneratedBy.Identity();
Map(model => model.Title).Not.Nullable().Length(100).Insert().Update();
}
}
public class AdvertPhotoMapping : BaseMapping<Advert> {
public AdvertPhotoMapping() : base("AdvertPhoto") {
Id(model => model.Advert)
.Column("Id")
.GeneratedBy.Foreign("Advert");
Map(model => model.Description).Nullable();
Map(model => model.Photo).CustomSqlType("image").Not.Nullable();
References(model => model.Advert, "Advert").Not.Nullable().Not.LazyLoad();
}
}
public class BidMapping { //: BaseMapping<Bid> {
public BidMapping() : base("Bid") {
Id(model => model.Advert, "Advert").GeneratedBy.Foreign("Advert");
CompositeId()
.KeyReference(model => model.Advert, "Advert")
.KeyReference(model => model.User, "User");
Map(model => model.Value).Not.Nullable().Insert().Update();
References(model => model.Advert, "Advert").Not.Nullable().Not.LazyLoad();
}
}
好吧,我當Fluent NHibernate嘗試引用AdvertPhotoMapping
類中的Advert列時我得到一個異常,我不知道BidMapping
CompositeId是否已正確映射。
我得到的例外是:
{"Could not determine type for: SYB.Engine.Entities.Advert, SYB.Engine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, for columns: NHibernate.Mapping.Column(Advert)"}
我在做什麼錯? 謝謝大家!