0

I'm trying to build an ASP .Net Core application and I'm exploring using Entity Framework Core through Code First.

I've previously always used a separate DbContext for Identity to the application bits, however, I want to neaten the code in this application.

I've tried looking in to Identity Framework's IdentityDbContext the best I can but, I'm no expert at decompiling (looking through Dotpeek).

Whilst I see some references to DbContextOptions, I can't see it actually directly inheriting DbContext anywhere.

So, my questions are:

  1. Do I need to and do I lose anything just by using the default generated code of:

    public class ApplicationDbContext : IdentityDbContext
    

    or should I be also inheriting DbContext?

  2. When trying to call the context directly, I don't seem to have some of the user methods I've been reading in examples (such as this link). I have seen example code similar to:

    public class ApplicationDbContext : IdentityDbContext<User, UserClaim, UserSecret, UserLogin, Role, UserRole, Token, UserManagement>
    

    Is this safe and/or are there any downsides?

Dev X
  • 89
  • 9
  • 3
    `IdentityDbContext` [inherits](https://github.com/aspnet/AspNetCore/blob/master/src/Identity/EntityFrameworkCore/src/IdentityDbContext.cs#L78) `IdentityUserContext` which in turn [inherits](https://github.com/aspnet/AspNetCore/blob/master/src/Identity/EntityFrameworkCore/src/IdentityUserContext.cs#L61) from `DbContext`, it's all in the source code. – DavidG Jan 21 '19 at 00:54
  • @DavidG - well, the answer is then that I do suck at using dotpeek as I missed the reference from IdentityUserContext to DbContext! ... If you can help with the second bit as well, (or even if you can't), feel free to write as an answer as you have helped a lot! – Dev X Jan 21 '19 at 01:01
  • I don't really understand you second question. Also, you should only pose a single question per post. – DavidG Jan 21 '19 at 01:03
  • Note that your second question links to the legacy version of Identity, not the one made for EF Core. – DavidG Jan 21 '19 at 01:05
  • @DavidG Sorry, understood - The first one (which you answered) is really what I was most interested about... The second is just annoying me and I didn't want to open too many questions... Basically, I just remember in a previous version when I had separate DbContexts, I was able to easily do GetUsers() or similar on the context itself and struggling to understand why I can't on the new version (and trying to do something like I have above is causing issues... which I understand if it is for the legacy version!). – Dev X Jan 21 '19 at 01:12
  • There was never a `GetUsers` method, there was a `Users` `DbSet` though, and there is the same property on the new one. – DavidG Jan 21 '19 at 01:13

0 Answers0