流利的nhibernate automapping集合 [英] Fluent nhibernate automapping collection
问题描述
$ b $ 1我希望项目中的所有集合都可以通过私有字段进行映射。 2)有没有什么方法可以自动映射双向关系,而不必显式覆盖每个实体。
类OrganizationEntity示例:
private ISet<> _collectionWarehouse;
pre>
public virtual IEnumerable< WarehouseEntity> CollectionWarehouse
{
get {return _collectionWarehouse; }($($)
$ b set {_collectionWarehouse = new HashedSet< WarehouseEntity>((ICollection< WarehouseEntity>)value)}
$ b
类WarehouseEntity示例:
public virtual OrganizationEntity Organization { ; set;}
解决方案私人领域'全球'与以下约定:
//假设骆驼大写下划线字段(即_mySet)
public class CollectionAccessConvention:ICollectionConvention
{
public void Apply(ICollectionInstance instance){
instance.Access.CamelCaseField(CamelCasePrefix.Underscore);
$ b当你想设置一个'全局'自动映射首选项在FNH,思考惯例。如果需要的话,您可以在给定的类映射上使用IAutoOverride。
到目前为止,HashSet通常也是我真正想要的部分,我不得不做一些映射,我确实需要做一个覆盖,如:
public class ActivityBaseMap:IAutoMappingOverride< ActivityBase>
{
public void Override(AutoMapping< ActivityBase> m)
{
...
m.HasMany(x => x.Allocations).AsSet )。逆();
$ b code
$ b我同意应该转换成一个惯例,也许你可以这样做。请发帖,如果你想出来。
HTH,
Berryl
使用HASHSET作为ICollection =================
public virtual ICollection< ; WarehouseEntity> Wharehouses
{
获得{return _warehouses (_warehouses = new HashSet< WarehouseEntity>()); }
set {_warehouses = value; }
}
private ICollection< WarehouseEntity> _warehouses;
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;}
解决方案You can map your collections to a private field 'globally' with the following convention:
// assumes camel case underscore field (i.e., _mySet) public class CollectionAccessConvention : ICollectionConvention { public void Apply(ICollectionInstance instance) { instance.Access.CamelCaseField(CamelCasePrefix.Underscore); } }
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:
public class ActivityBaseMap : IAutoMappingOverride<ActivityBase> { public void Override(AutoMapping<ActivityBase> m) { ... m.HasMany(x => x.Allocations).AsSet().Inverse(); } }
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,
BerrylCODE TO USE A HASHSET as an ICollection =================
public virtual ICollection<WarehouseEntity> Wharehouses { get { return _warehouses ?? (_warehouses = new HashSet<WarehouseEntity>()); } set { _warehouses = value; } } private ICollection<WarehouseEntity> _warehouses;
这篇关于流利的nhibernate automapping集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!