我的数据库在 mysql 中。一切正常,直到我将新列添加到我的表 CustomTagUser 。新列也是来自用户表的另一个 FK ,即 OwnerId 。
public class CustomTagUser
{
[Key]
public int CustomTagUserId { get; set; }
public int CustomTagId { get; set; }
public int UserId { get; set; }
public int OwnerId { get; set; } // newly added column
public DateTime CreatedOn { get; set; }
[ForeignKey("CustomTagId")]
public virtual CustomTags CustomTags { get; set; }
[ForeignKey("UserId")]
public virtual User User { get; set; }
[ForeignKey("OwnerId")] // added for navigation
public virtual User Owner { get; set; } // added for navigation
}
public class User
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
public string Password { get; set; }
public ICollection<UserSetting> UserSettings { get; set; }
public ICollection<UserRoles> Roles { get; set; }
public ICollection<UserPreference> Preference { get; set; }
public ICollection<CustomTagUser> CustomTagUser { get; set; }
}
当我点击下面的查询时,它会在“字段列表”中显示未知列'Extent2.User_UserId'在添加新列之前完全正常运行。此外,如果我删除所有者属性,它将不会抛出错误,但然后我将无法将引用的数据加载到该OwnerId。
var userDetail = dbContext.Users.Include(x => x.CustomTagUser.Select(y => y.CustomTags)).FirstOrDefault(c => c.UserId == peopleId);
我不知道我做错了什么。任何指导将非常感谢。