复合 ID 的自动映射不起作用
我正在使用 Sharp-Architecture 框架,并且有一个如下所示的实体:
public class BaanAlternateItemKey : ValueObject
{
public virtual string ItemId { get; protected set; }
public virtual string AlternateItemId { get; protected 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
}
我有一个如下所示的自动映射覆盖:
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");
}
}
我收到此异常:
----> NHibernate.MappingException:无法确定以下类型:iPFS.Core.Baan.BaanAlternateItemKey,iPFS.Core,Version = 0.0.4154.21888,Culture =中性,PublicKeyToken = null,对于列:NHibernate.Mapping.Column(Id)
我没有知道我做错了什么。有什么建议吗?
更新:如果我使用流畅的映射来映射它,它可以正常工作:
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");
}
}
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; protected 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");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不应该是这样吗?:
此错误表明映射引擎不知道
BaanAlternateItemKey
类型的任何映射。因此,请确保您有地图。Is that shouldn't be that?:
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.我相信您需要将 AlternateItemId 的 KeyProperty 映射转换为 KeyReference,然后删除引用映射,如下所示。这假设该 Item 也已被映射,并且它具有指定的与 ALT_ITEM_ID 值匹配的 Id 属性。
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.