gpt4 book ai didi

c# - FluentNhibernate - 已添加时尝试添加多对一 'Document'

转载 作者:太空宇宙 更新时间:2023-11-03 19:11:20 25 4
gpt4 key购买 nike

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

Tried to add many-to-one 'Document' when already added.

这是我的代码:

   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();
}

哪里出错了?

谢谢。

最佳答案

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

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

关于c# - FluentNhibernate - 已添加时尝试添加多对一 'Document',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20363050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com