我正在尝试将属性 CilentID 添加到 AspNetUsers 表,这是客户表的FK :(非ENTITY FRAMEWORK)< / p>
SQL:
IdentityModels:
public class ApplicationUser : IdentityUser
{
[ForeignKey("Client")]
public int ClientID { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
return userIdentity;
}
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public DbSet<Client> Clients { get; set; }
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
客户端
[Table("Client")]
public class Client
{
[Key]
public int ClientID { get; set; }
public string ClientName { get; set; }
public string Description { get; set; }
}
我收到以下错误:
“Proj.Models.ApplicationUser”类型的属性“ClientID”上的ForeignKeyAttribute无效。在依赖类型'proj.Models.ApplicationUser'上找不到导航属性'Client'。 Name值应该是有效的导航属性名称。
我缺少什么?