我的班级
public class DocumentSale
{
public List<DocumentSale> FollowDocuments {get; set;}
public List<DocumentSale> BaseDocuments {get; set;}
}
如何在实体框架上映射它?我收到错误
关系“DocumentSaleDocumentSales”的“FK_dbo.DocumentSaleDocumentSales_public.saledocument_DocumentSa”已经存在
我的数据库是postgres 9.4.9
答案 0 :(得分:0)
你可以试试这样的事情
public class DocumentSale
{
[Key]
public int Id { get; set; }
public int? FollowDocumentId { get; set; }
public int? BaseDocumentId { get; set; }
public virtual DocumentSale FollowDocument { get; set; }
public virtual DocumentSale BaseDocument { get; set; }
[ForeignKey(nameof(FollowDocumentId))]
public virtual List<DocumentSale> FollowDocuments { get; set; }
[ForeignKey(nameof(BaseDocumentId))]
public virtual List<DocumentSale> BaseDocuments { get; set; }
}
答案 1 :(得分:0)
这就是我所需要的:
public class DocumentSale
{
public List<DocumentSale> FollowDocuments {get; set;}
public List<DocumentSale> BaseDocuments {get; set;}
}
modelBuilder.Entity<DocumentSale>()
.HasMany<DocumentSale>(c => c.baseDocuments)
.WithMany(c => c.followUpDocuments)
.Map(
cs =>
{
cs.MapLeftKey("followdocid");
cs.MapRightKey("basedocid");
cs.ToTable("basefollow");
}
);