I'm using the Sharp-Architecture framework and I have an entity that looks like this:
public class BaanAlternateItemKey : ValueObject
{
public virtual string ItemId { get; protected set; }
public virtual string AlternateItemId { get; protect开发者_如何学运维ed set; }
}
public class BaanAlternateItem : EntityWithTypedId<BaanAlternateItemKey>, IAlternateItem
{
#region IAlternateItem Members
public virtual IItem Item { get; protected set; }
public virtual int Priority { get; protected set; }
public virtual DateTime ExpirationDate { get; protected set; }
#endregion
}
I have an auto mapping override that looks like this:
public class BaanAlternateItemAutoMappingOverride : IAutoMappingOverride<BaanAlternateItem>
{
public void Override(AutoMapping<BaanAlternateItem> mapping)
{
mapping.ReadOnly();
mapping.Table("VIEW_BAAN_ALTERNATE_ITEMS");
mapping.CompositeId<BaanAlternateItemKey>(x => x.Id)
.KeyProperty(x => x.ItemId, "ITEM_ID")
.KeyProperty(x => x.AlternateItemId, "ALT_ITEM_ID");
mapping.References<BaanItem>(x => x.Item, "ALT_ITEM_ID");
}
}
I'm getting this exception:
----> NHibernate.MappingException : Could not determine type for: iPFS.Core.Baan.BaanAlternateItemKey, iPFS.Core, Version=0.0.4154.21888, Culture=neutral, PublicKeyToken=null, for columns: NHibernate.Mapping.Column(Id)
I have no idea what I'm doing wrong. Any suggestions?
UPDATE: If I map this using fluent mapping it works fine:
public class BaanAlternateItemMap : ClassMap<BaanAlternateItem>
{
public BaanAlternateItemMap()
{
ReadOnly();
Table("VIEW_BAAN_ALTERNATE_ITEMS");
CompositeId<BaanAlternateItemKey>(x => x.Id)
.KeyProperty(x => x.ItemId, "ITEM_ID")
.KeyProperty(x => x.AlternateItemId, "ALT_ITEM_ID");
Map(x => x.Priority, "PRIORITY");
Map(x => x.ExpirationDate, "EXPIRATION_DATE").CustomType("Timestamp");
References<BaanItem>(x => x.Item, "ALT_ITEM_ID");
}
}
Is that shouldn't be that?:
public class BaanAlternateItemAutoMappingOverride : IAutoMappingOverride<BaanAlternateItem>
{
public void Override(AutoMapping<BaanAlternateItem> mapping)
{
mapping.ReadOnly();
mapping.Table("VIEW_BAAN_ALTERNATE_ITEMS");
mapping.CompositeId<BaanAlternateItem>(x => x.Id) //are you mapping BaanAlternateItem right?
.KeyProperty(x => x.ItemId, "ITEM_ID")
.KeyProperty(x => x.AlternateItemId, "ALT_ITEM_ID");
mapping.References<BaanItem>(x => x.Item, "ALT_ITEM_ID");
}
}
This error says that the mapping engine have no idea about any map for type BaanAlternateItemKey
. So make sure that you have map for it.
I believe you'll want to convert the KeyProperty mapping for AlternateItemId to a KeyReference and then remove the References mapping as shown below. This assumes the Item has been mapped also and it has an Id property designated that matches the ALT_ITEM_ID value.
public class BaanAlternateItemAutoMappingOverride : IAutoMappingOverride<BaanAlternateItem>
{
public void Override(AutoMapping<BaanAlternateItem> mapping)
{
mapping.ReadOnly();
mapping.Table("VIEW_BAAN_ALTERNATE_ITEMS");
mapping.CompositeId<BaanAlternateItem>(x => x.Id) //are you mapping BaanAlternateItem right?
.KeyProperty(x => x.ItemId, "ITEM_ID")
.KeyReference(x => x.Item, "ALT_ITEM_ID");
}
}
精彩评论