C# 构建数据库后,Guid不是外键。ASP.NET核心标识3.1
我在这里使用ASP.NET标识,但我有一些问题,我想用一些属性扩展它。我添加了类应用程序user,它继承自identity用户C# 构建数据库后,Guid不是外键。ASP.NET核心标识3.1,c#,asp.net-identity,asp.net-core-3.1,C#,Asp.net Identity,Asp.net Core 3.1,我在这里使用ASP.NET标识,但我有一些问题,我想用一些属性扩展它。我添加了类应用程序user,它继承自identity用户 public class UserInfo : IdentityUser { public virtual UserProfileInfo ProfileInformation { get; set; } } public class UserProfileInfo { [Key] public int Id { get; set; }
public class UserInfo : IdentityUser
{
public virtual UserProfileInfo ProfileInformation { get; set; }
}
public class UserProfileInfo
{
[Key]
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
MyDbContext
:
public class MISDBContext : IdentityDbContext<UserInfo>
{
public MISDBContext(DbContextOptions<MISDBContext> options)
: base(options) { }
public DbSet<MISObject> MISobject { get; set; }
public DbSet<ApplicationUser> AppUsers { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
我的Startup.cs
public void ConfigureServices(IServiceCollection services) {
services.AddDbContext<MISDBContext>
(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddControllersWithViews();
services.AddRazorPages();
}
public void配置服务(IServiceCollection服务){
services.AddDbContext
(options=>options.UseSqlServer(Configuration.GetConnectionString(“DefaultConnection”));
services.AddDbContext
public void ConfigureServices(IServiceCollection services) {
services.AddDbContext<MISDBContext>
(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddControllersWithViews();
services.AddRazorPages();
}