查看我的模特
public class UsersContext : DbContext
{
public UsersContext()
: base("DefaultConnection")
{
}
public DbSet<UserProfile> UserProfiles { get; set; }
public DbSet<Files> Files { get; set; }
}
[Table("UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
}
[Table("Files")]
public class Files
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
[Display(Name = "FileID")]
public int FileID { get; set; }
[Required]
[ForeignKey("UserId")] // this is what I have tried
[Display(Name = "For User")]
public int UserId { get; set; }
[Display(Name = "Description")]
public string Desc { get; set; }
[Required]
[Display(Name = "Document Upload")]
public string DocumentPath { get; set; }
}
我想要的是在文件表中为用户ID定义外键。我应该如何做到这一点。我尝试使用[ForeignKey]
属性。但它在PCM中执行update-database -verbose
时给出了这个错误。
错误 - 导航属性“UserId”不是声明的属性 输入'文件'。验证它是否未被明确排除 模型,它是一个有效的导航属性。
答案 0 :(得分:2)
Router.go('post_page', {_id: vai});