more than one navigation to the same entity

后端 未结 1 1933
半阙折子戏
半阙折子戏 2021-01-13 07:32

I have a problem with connection between 2 entities when there is 2 navigations.

to be specific, I have the following classes:

public class TableA
{
         


        
相关标签:
1条回答
  • 2021-01-13 07:35

    use this Code :

    public class TableA
    {
        public TableA()
        {
            ListBs = new List<TableB>();
        }
    
        [Key]
        public int Id { get; set; }
    
        public int TableB_Id { get; set; }
    
        [InverseProperty("TableA_Mains")]
        [ForeignKey("TableB_Id")]
        public TableB MainB { get; set; }
    
        [InverseProperty("refA")]
        public virtual ICollection<TableB> ListBs { get; set; }
    }
    
    public class TableB
    {
        [Key]
        public int Id { get; set; }
    
        public int TableA_Id { get; set; }
    
        [Foreignkey("TableA_Id")]
        [InverseProperty("ListBs")]
        public virtual TableA refA { get; set; }
    
        [Required]
        public string Text { get; set; }
    
    
        [InverseProperty("MainB")]
        public virtual ICollection<TableA> TableA_Mains { get; set; }
    
    }
    
    0 讨论(0)
提交回复
热议问题