Entity framework 实体框架插入错误

Entity framework 实体框架插入错误,entity-framework,Entity Framework,我有三张课桌 和类别表有1条记录,例如catID=2。。。 并且没有产品表的记录 现在,在向表映像添加新记录时, 当我输入CategpryID=2,ProductID=0时。。。 我得到一个错误: 我需要什么* 如果能在您的问题中获取异常类型和消息,我会认为ProductID=0抛出了一个外键错误。很可能不会有ID为0的产品。 [Table("Products")] public class Product { public Product() { Images

我有三张课桌 和类别表有1条记录,例如catID=2。。。 并且没有产品表的记录

现在,在向表映像添加新记录时, 当我输入CategpryID=2,ProductID=0时。。。 我得到一个错误: 我需要什么*


如果能在您的问题中获取异常类型和消息,我会认为ProductID=0抛出了一个外键错误。很可能不会有ID为0的产品。
[Table("Products")]
public class Product
{
    public Product()
    {
        Images = new List<Image>();
    }

    public int ProductID { get; set; }
    public string Name { get; set; }

    public List<Image> Images { get; set; }
}

[Table("Categorys")]
public class Category
{
    public Category()
    {
        Images = new List<Image>();
    }
    public int CategpryID { get; set; }
    public string Name { get; set; }

    public List<Image> Images { get; set; }
}

[Table("Images")]
public class Image
{
    [Key]
    public int ImageID { get; set; }

    public int CategpryID { get; set; }
    public int ProductID { get; set; }

    public string ImageURL { get; set; }

    public Product Product { get; set; }
    public Category Category { get; set; }
}