3

I want to use Microsoft Identity in my project that using entity framework core in database first approach. The project type is asp.net core, mvc(.net core 3.1) help me please.

1
  • Do not inherit your DatabaseContext class form DBContext. inherit from IdentityDbContext and use it like normal DatabaseContext. Commented Dec 7, 2020 at 8:40

2 Answers 2

1

Add two separate class library projects into your solution one for IdentityContext and one for ApplicationDbContext.

public class IdentityContext : IdentityDbContext<IdentityUser>
{
    public IdentityContext(DbContextOptions<IdentityContext> options) : base(options)
    {
    }
}

public class ApplicationDbContext : DbContext
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
    {
    }
}

Add your entities to ApplicationDBContext class as well as the required ModelBuilder.

Add extension services to each project and add appropriate dbContext service to both. Now you can execute EF Core Migration command separately for each project to create and add tables for User membership and your application main tables. I strongly recommend taking a look at this github resource (Infrastructure.Identity and Infrastructure.Persistence) for more details.

Sign up to request clarification or add additional context in comments.

Comments

0

when you create a project and choose "individual user accounts" in visual studio, Microsoft Identity add automatically to your project as a Razor class library which means, Register and Login UI and functionality, Authentication and Authorization services and... is there from before.
Please tell me what exactly is your problem ?

1 Comment

I just want to mix the Identity module (that you said above) with my database in db first mode. Exactly like ef code first mode when using identity. So, i don't know how can i use the identity in my code in db first mode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.