Fluent nhibernate 自动映射集合
我正在尝试使用 FNHib 自动映射来映射我的集合。我想解决的问题是:
1)我希望项目中的所有集合都通过私有字段映射。我怎么能在全球范围内这么说呢?
2)有没有什么方法可以自动映射双向关系,而无需显式覆盖我的每个实体。
类 OrganizationEntity 示例:
private ISet<> _collectionWarehouse;
public virtual IEnumerable<WarehouseEntity> CollectionWarehouse
{
get{return _collectionWarehouse; }
set{_collectionWarehouse = new HashedSet<WarehouseEntity>((ICollection<WarehouseEntity>)value)}
}
类 WarehouseEntity 示例:
public virtual OrganizationEntity Organization{get;set;}
I am trying to map my collections with FNHib automapping. The problems that I want to solve are:
1) I want all my collections in the project to be mapped via private field. How can I say that globally?
2) Is there any way to automap bidirectional relationship without explicitly overriding each of my entities.
class OrganizationEntity example:
private ISet<> _collectionWarehouse;
public virtual IEnumerable<WarehouseEntity> CollectionWarehouse
{
get{return _collectionWarehouse; }
set{_collectionWarehouse = new HashedSet<WarehouseEntity>((ICollection<WarehouseEntity>)value)}
}
Class WarehouseEntity example:
public virtual OrganizationEntity Organization{get;set;}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下约定将集合“全局”映射到私有字段:
每当您想在 FNH 中设置“全局”自动映射首选项时,请考虑约定。如果需要,您可以在给定的类映射上使用 IAutoOverride。
就集合(哈希集通常也是我真正想要的)部分而言,上次我必须做一些映射时,我确实需要进行覆盖,例如:
我确实同意应该转化为约定,并且也许现在你可以做到这一点。如果你弄清楚了请发帖。
HTH,
Berryl代码 =================
使用 HASHSET 作为 ICollection 的
You can map your collections to a private field 'globally' with the following convention:
Whenever you want to set a 'global' automap preference in FNH, think conventions. The you use the IAutoOverride on a given class map if you need to.
As far has the set (a HashSet is usually what I really want also) part, the last time I had to do some mapping, I did need to do an override, like:
I do agree that should translate into a convention though, and maybe you can do that these days. Please post if you figure it out.
HTH,
Berryl
CODE TO USE A HASHSET as an ICollection =================