FluentNhibernate - 试图在添加时添加多对一的“文档”

时间:2013-12-03 22:30:06

标签: c# nhibernate fluent-nhibernate hibernate-mapping

我没有得到我的映射代码,总是出现同样的错误: 当我启动应用程序来创建表时,它显示以下错误

  

尝试添加多对一'文档'时已添加。

这是我的代码:

   public class DocTypes
        {
            public virtual Int16 Id { get; private set; }
            public virtual IList<Documents> Documents { get; set; }        
        }


   public class Documents
        {
            public virtual Int64 Id { get; private set; }
            public virtual DocTypes DocType { get; set; }
            public virtual IList<Files> Files { get; set; }
            public virtual IList<Fields> Fields { get; set; }               
        }
 public class Fields
    {

        public virtual Int32 Id { get; private set; }
        public virtual Documents Document { get; set; }    
    }

我的映射:

public DocTypeMap()
        {
            Table("TbDocType");
            Id(x => x.Id)
               .Column("Num_Id");            
            HasMany(x => x.Documents)
               .KeyColumn("Num_DocType_Id")
               .Inverse()
               .Cascade.All();
            References(x => x.Cabinet, "Num_Cabinets_Id").Cascade.None();
        }
 public DocumentsMap()
        {
            Table("TbDocuments");
            Id(x => x.Id)
             .Column("Num_Id");

            HasMany(x => x.Files)
             .KeyColumn("Num_Document_Id")
             .Inverse()
             .Cascade.All();
            HasMany(x => x.Fields)
             .KeyColumn("Num_Document_Id")
             .Inverse()
             .KeyNullable()
             .Cascade.All();
            References(x => x.DocType, "Num_DocType_Id").Cascade.None();

        }

   public FieldsMap()
        {
            Table("TbFields");
            Id(x => x.Id)
                .Column("Num_Id");
            References(x => x.Document, "Num_Document_Id")
                .Cascade.None();
            References(x => x.Document, "Num_BarCode_Id")
                .Cascade.None();
        }

错误在哪里?

谢谢。

1 个答案:

答案 0 :(得分:6)

您似乎在Document中两次引用FieldsMap。这里:

References(x => x.Document, "Num_Document_Id")
    .Cascade.None();
References(x => x.Document, "Num_BarCode_Id")
    .Cascade.None();