繁体   English   中英

外键和 DBMS 图错误,无法将外键分配给更多表,实体框架核心错误。 有人请指导我

[英]Foreign Key And DBMS Diagram Error , Cannot Assign Foreign Key to More Tables, Entity Framework Core Error. Someone Please Guide me

这是 ERM 图。 我在最后附上了错误截图。 这是 ERM 图

我在这里提到代码。

这是 Recepies.cs 文件

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace SolomonCookBook.Models{
    public class Recepies{
        [Key]
        public int Recepie_ID{get;set;}
        public string Recepie_Name{get;set;}
        public string Category {get;set;}
        public string video_url{get;set;}
        public string image_url{get;set;}
        public string Ingredients{get;set;}
        public int Likes{get;set;}
        public string Comments{get;set;}

        [ForeignKey("User")]
        public int User_ID{get;set;}
        public User User{get;set;}


        

    }
}

这是 User.cs Model 文件

using System.ComponentModel.DataAnnotations;
namespace SolomonCookBook.Models{
    public class User{
        [Key]
        public int User_ID{get;set;}
        public string First_name{get;set;}

        public string Last_name{get;set;}
        public string Email{get;set;}
        public string Phone_number{get;set;}
        public string Password{get;set;}

        public ICollection <Recepies> Recepies{get;set;}
    }
}

这是 Recepie_Comments.cs 代码,这里发生错误

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace SolomonCookBook.Models{
    public class Recepie_Comments{
        [Key]
        public int R_like_ID{get;set;}

        [ForeignKey("User_ID")]
        public int User_ID_{get;set;}
        public User User {get;set;}


        [ForeignKey("Recepie_ID")]
        public int Recepie_ID_ {get;set;}
        public Recepies Recepie {get;set;}

        public DateTime Date{get;set;} 
    }
}

错误是:

错误截图

错误截图续

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM