0
我有一個用戶配置類域類建模衝突
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
}
而且
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;
}
}
我有一個很難搞清楚如何在用戶配置兩個集合(AuthoredBlogs模型和相關博客類SubscribedBlogs)和Blog類。在UserProfile中擁有這兩個集合需要兩個FK關聯到Blog,但我不知道該如何/應該如何工作。
UserProfile可以訂閱並創作許多博客。但是Blog類只能有一個作者和一個訂閱的UserProfiles列表,或者像我這裏的那樣,有一個訂閱者的UserProfileId列表。
我不能得到它的工作,由於FK協會問題代碼第一次更新未能部署到數據庫。
任何幫助表示讚賞。
...虐待它,看看 – dinotom