gpt4 book ai didi

c# - 1对1关系EF两个外键报错

转载 作者:太空宇宙 更新时间:2023-11-03 15:15:21 26 4
gpt4 key购买 nike

<分区>

    public class Picture
{
[Key]
public int Id { get; set; }

public int NewsId { get; set; }
[ForeignKey("NewsId")]
public virtual News News { get; set; }

public int PostId { get; set; }
[ForeignKey("PostId")]
public virtual Post Post { get; set; }
}

public class News
{
public int Id { get; set; }
public virtual Picture Picture { get; set; }
}

public class Post
{
public int Id { get; set; }
public virtual Picture Picture { get; set; }
}

异常(exception):

Unable to determine the principal end of an association between the types 'Project.BusinessObjects.Photo' and 'Project.BusinessObjects.Student'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.

怎么了?

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