我有一个 UserProfile 类
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
}
以及相关的 Blog 类
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;
}
}
我很难弄清楚如何使用 Blog 类对 UserProfile(AuthoredBlogs 和 SubscribedBlogs)中的两个集合进行建模。在 UserProfile 中拥有这两个集合需要两个 FK 关联到博客,但我只是不明白这可以/应该如何工作。
UserProfile 可以订阅和创作许多博客。但是 Blog 类只能有一个作者和订阅的 UserProfiles 列表,或者像我在这里拥有的那样,是订阅者的 UserProfileId 列表。
我无法让它工作,由于 FK 关联问题,代码优先更新无法部署到数据库。
任何帮助表示赞赏。