流利的nhibernate 1.2自我参考反对收集多对多

时间:2011-06-22 08:18:35

标签: nhibernate fluent-nhibernate nhibernate-mapping

我刚从nHib 2.1.2用流利的nHib 1.2升级到nHib 3.1,最新流利的nHib(也是1.2)。
现在,突然间,我的员工实体上出现了映射异常 员工包含管理员工的列表,以及管理员的反向列表 像这样:

public virtual IEnumerable<Employee> ManagedEmployees { get; private set; }
public virtual IEnumerable<Employee> Managers { get; private set; }

我正在使用Automapping,这个映射覆盖,之前完美无缺:

mapping.HasManyToMany(x => x.ManagedEmployees).Cascade.SaveUpdate()
                .Table("ManagersToEmployees").ParentKeyColumn("Manager_id").ChildKeyColumn("Employee_id")
                .AsSet()
                .Not.LazyLoad()
                .Fetch.Subselect()
                ;

mapping.HasManyToMany(x => x.Managers).Cascade.None()
                .Table("ManagersToEmployees").ParentKeyColumn("Employee_id").ChildKeyColumn("Manager_id")
                .Inverse()
                .AsSet()
                ;

现在它会生成错误说:

FluentNHibernate.Visitors.ValidationException: The relationship Employee.Managers to Employee.Managers has Inverse specified on both sides. Remove Inverse from one side of the relationship..  

有人知道吗?

修改
这是FNH中确认的错误。基于this workaround我将自动配置更改为:

    .Mappings(m => 
                        {
                           var autoPersistenceModel = AutoMap.AssemblyOf<Domain.Employee>(cfg)      //automapping the domain entities

.UseOverridesFromAssemblyOf<MappingOverrides.DepartmentMappingOverride>();

                           autoPersistenceModel.ValidationEnabled = false;

                            m.AutoMappings.Add(
                             autoPersistenceModel
                        );                
                     }
                    );

0 个答案:

没有答案