域 class 建模冲突

Domain class modelling conflict

我有一个用户配置文件class

 public class UserProfile
{
    public UserProfile()
    {
    }

    public UserProfile(string userId)
    {
        AppUserId = userId;
    }

    [Key]
    public int UserProfileId { get; set; }

    public string AppUserId { get; set; }
    public ICollection<Blog> AuthoredBlogs { get; set; }
    public ICollection<Blog> SubscribedBlogs { get; set; }

    //other properties removed for brevity
}

以及相关的博客 class

 public class Blog
{
    [Key]
    public int BlogId { get; set; }

    [ForeignKey("BlogAuthor")]
    [Index("IX_AuthorIndex", 1, IsClustered = false, IsUnique = false)]
    public int AuthorId { get; set; }

    [Required]
    public Author BlogAuthor { get; set; }

    [Required(ErrorMessage = "A blog name is required")]
    public string BlogName { get; set; }

    public string BlogIconUrl { get; set; }
    public List<BlogPost> BlogPosts { get; set; }

    public EquipmentCategory EquipmentCategory { get; set; }       
    public EquipmentType EquipmentType { get; set; }

    public ICollection<int> BlogReaderIds { get; set; }

    public Blog(string name, Author author)
    {
        BlogName = name;
        BlogAuthor = author;
        EquipmentType = EquipmentType.NoSearch;
        EquipmentCategory = EquipmentCategory.NoSearch;
    }

    public Blog()
    {
        EquipmentType = EquipmentType.NoSearch;
        EquipmentCategory = EquipmentCategory.NoSearch;
    }
}

我很难弄清楚如何使用博客对 UserProfile 中的两个集合(AuthoredBlogs 和 SubscribedBlogs)建模 class。在 UserProfile 中拥有这两个集合将需要两个 FK 关联到博客,但我只是不明白 can/should 是如何工作的。

一个 UserProfile 可以订阅和创作许多博客。但是博客 class 只能有一个作者和订阅的 UserProfiles 列表,或者,如我这里所列,订阅者的 UserProfileId 列表。

我无法让它工作,由于 FK 关联问题,代码优先更新无法部署到数据库。

感谢任何帮助。

这些模型注释将通过自动创建、shadow table 在作者和博客之间创建一对多关系,在博客和订阅者之间创建多对多关系.

public class UserProfile
{
    //other stuff...

    [InverseProperty("Autor")]
    public ICollection<Blog> AuthoredBlogs { get; set; }
    [InverseProperty("SubscribedUserProfiles")]
    public ICollection<Blog> SubscribedBlogs { get; set; }   
}

public class Blog
{
    //other stuff..

    public ICollection<UserProfile> SubscribedUserProfiles { get; set; }        

    public UserProfile Autor { get; set; }
    [ForeignKey("Autor")]
    public int AutorId { get; set; }
}