I am working on an asp.net-core 2.0 project.
This project contains a database with Entity Framework Core. I am working on Code First mode with migrations.
What i want to do is to create some default datas in my database on structure creation.
I need to create an User.
I have looked in OnModelCreating function in my IdentityDbContext class but i have no way to access to userManager object.
So i do not know how to do.... Thanks
Here is my code:
public class MyContext : IdentityDbContext<Utilisateurs>
{
public static string ConnectionString;
public MyContext()
{
}
public MyContext(DbContextOptions<pluginwebContext> options) : base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(MyContext.ConnectionString);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
var user = new MyUserClass { UserName = "test" };
// Error There
var result = await _userManager.CreateAsync(user, "1234");
}
public DbSet<MyTable1> table1 { get; set; }
...
}