C# FluentNHibernate具有许多约定覆盖

C# FluentNHibernate具有许多约定覆盖,c#,nhibernate,fluent-nhibernate,many-to-many,fluent-nhibernate-mapping,C#,Nhibernate,Fluent Nhibernate,Many To Many,Fluent Nhibernate Mapping,我和FluentNhibernate一起工作。我正试图使我的地图文件尽可能轻量级,方法是在表名、外键列等方面依赖约定文件 我对我的草率承诺有点问题 我有两个目标。Models.Processor和Models.Worker 一个处理器可以与许多工作者关联,反之亦然 public class Processor : Entity { ... public virtual IList<Worker> Workers { get; set; } public vir

我和FluentNhibernate一起工作。我正试图使我的地图文件尽可能轻量级,方法是在表名、外键列等方面依赖约定文件

我对我的草率承诺有点问题

我有两个目标。Models.Processor和Models.Worker

一个处理器可以与许多工作者关联,反之亦然

public class Processor : Entity
{
    ...
    public virtual IList<Worker> Workers { get; set; }
    public virtual void AddWorker(Worker worker)
    {
        worker.AddProcessor(this);
        Workers.Add(worker);
    }
}

public class Worker : Entity
{
    ...
    public virtual IList<Processor> Processors { get; set; }
    public virtual void AddProcessor(Processor processor)
    {
        processor.AddWorker(this);
        Processors.Add(processor);
    }
}
所以,当我调试它时,会发生什么,就是它进入方法GetBiDirectionalTableName,出于某种原因,集合和其他端属性都是Processor类型。我本以为一个是处理器,一个是工人。结果是FN抛出以下异常

NHibernate.MappingException : Repeated column in mapping for collection:
    Core.Models.Processor.Workers column: ProcessorId

任何帮助/指示都将不胜感激。

结果表明,我在HasManyToMany映射中缺少了一些额外的参数


您需要指定其中一个是反向的

您使用什么版本的fluentnhibernate?我记得有一个版本有这个bug。
public class ForeignKeyConvention : FluentNHibernate.Conventions.ForeignKeyConvention
{
    protected override string GetKeyName(Member property, Type type)
    {
        if (property == null)
            return type.Name + "Id";

        return property.Name + "Id";
    }
}

public class HasManyToManyConvention : IHasManyToManyConvention
{
    public void Apply(IManyToManyCollectionInstance instance)
    {
        instance.Cascade.SaveUpdate();
    }
}

public class ManyToManyTableNameConvention :
             FluentNHibernate.Conventions.ManyToManyTableNameConvention
{
    protected override string GetBiDirectionalTableName(
              IManyToManyCollectionInspector collection,
              IManyToManyCollectionInspector otherSide)
    {
        return collection.EntityType.Name + otherSide.EntityType.Name;
    }

    protected override string GetUniDirectionalTableName(
              IManyToManyCollectionInspector collection)
    {
        return collection.EntityType.Name + collection.ChildType.Name);
    }
}
NHibernate.MappingException : Repeated column in mapping for collection:
    Core.Models.Processor.Workers column: ProcessorId