我试图创建一个一对一的关系使用C#在实体框架6使用ASP.NET MVC 5内置用户身份验证。如何在ASP.NET MVC 5实体框架6中使用流畅的API映射表?
我能够使用实体框架创建的默认值创建表和连接。但是,当我尝试使用流利的API ......更具体地说,当我使用模型创建甚至是空的时候,使用包管理器控制台的数据库迁移将失败。我如何映射我的一对一关系?
我的错误:
//error
//my.Models.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. //Define the key for this EntityType.
//my.Models.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. //Define the key for this EntityType.
//IdentityUserLogins: EntityType: EntitySet 'IdentityUserLogins' is based on type //'IdentityUserLogin' that has no keys defined.
//IdentityUserRoles: EntityType: EntitySet 'IdentityUserRoles' is based on type //'IdentityUserRole' that has no keys defined.
我的代码:
namespace my.Models
{
public class ApplicationUser : IdentityUser
{
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
public DbSet<EngineeringProject> EngineeringProjects { get; set; }
public DbSet<EngineeringProject> EngineeringDesigns { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new EngineeringDesignMap());
modelBuilder.Configurations.Add(new EngineeringProjectMap());
}
}
}
namespace my.Models.Mapping
{
public class EngineeringProjectMap : EntityTypeConfiguration<EngineeringProject>
{
public EngineeringProjectMap()
{
this.HasRequired(t => t.EngineeringPd)
.WithOptional(t => t.EngineeringProject);
this.HasRequired(t => t.EngineeringProjectCategory)
.WithMany(t => t.EngineeringProjects)
.HasForeignKey(d => d.CategoryId);
}
}
}
_has没有定义关键字_什么不明白你? “IdentityUser”的外观是什么? –