使用最新的asp.net5 RC1,我正在尝试创建一个简单的User实体和WorkLog实体之间的关系。
使用Identity中的ApplicationUser类作为起点,并使用定义为链接键的ApplicationUser密钥是否可行?过去我曾尝试扩展ApplicationUser并遇到了问题,因此我生成了一个指向相同数据库的单独的dbcontext,并创建了自己的管道以将IdentityUsers Id传递到我的单独的dbcontext。是否有人有扩展IdentityDbContext并添加映射到IdentityUser类的外键表的示例?
以下是示例:
使用Identity中的ApplicationUser类作为起点,并使用定义为链接键的ApplicationUser密钥是否可行?过去我曾尝试扩展ApplicationUser并遇到了问题,因此我生成了一个指向相同数据库的单独的dbcontext,并创建了自己的管道以将IdentityUsers Id传递到我的单独的dbcontext。是否有人有扩展IdentityDbContext并添加映射到IdentityUser类的外键表的示例?
以下是示例:
//DBContext
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public DbSet<WorkLogItem> WorkLogItems { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
builder.Entity<WorkLogItem>(
e =>
{
e.Property(p => p.id).IsRequired().UseSqlServerIdentityColumn();
});
}
}
//WorkLogItem
public class WorkLogItem
{
public int id { get; set;}
public String UserId { get; set; }
public int Hours { get; set; }
public String Description { get; set; }
}
//ApplicationUser
public class ApplicationUser : IdentityUser
{
public ICollection<WorkLogItem> WorkLogItems { get; set; }
}