0

I have looked and havent seen anything on this, most information relates to directly extending Identity tables.

I have extended Application User like so:

 public class ApplicationUser : IdentityUser<long> { //[Key()] //public long Id { get; set; } [Required()] [MaxLength(100)] public string Password { get; set; } [Required()] [MaxLength(100)] override public string UserName { get; set; } [Required()] [MaxLength(50)] public string FirstName { get; set; } [Required()] [MaxLength(50)] public string LastName { get; set; } public virtual Organization Organization { get; set; } } public class ApplicationRole : IdentityRole<long> { } 

along with other neccesary changes to ApplicationDbContext (to change the primary key to long). Other than that, its fairly standard Identity stuff. I add migrations, update; the usual tables are created plus Organization table because it's a navigation property. Organization itself has no navigation properties. Keep in mind, for the most part I was handed these classes as part of a project and am trying to work within the confines of what I've been given. Now, I have several classes that I need to add, one as an example:

 public class Event { [Key()] public long Id { get; set; } [Required()] [MaxLength(200)] public string Name { get; set; } [Index] public virtual Organization Organization { get; set; } } 

There are a handful of other something inter related classes. So in a standard code first core 2 app with no existing db, I would create the context class that derives from DbContext, whereas in Identity ApplicationDbContext (the default name) derives from IdentityDbContext.

So before I start breaking things, are there any concerns or special considerations before I do something like this?

 public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { public DbSet<Event> Events{ get; set; } public DbSet<OtherClass> OtherClasses{ get; set; } } 

Note: I did find this post which seems to do what I am talking about but it is for MVC 5

1
  • Actually you'll break the things (or get unpleasant unexpected results) if you don't do that (I mean, if you don't use single db context for identity and your tables). Commented Mar 22, 2018 at 17:24

1 Answer 1

1

You can just add the classes as properties, i.e. public DbContext<Class> Classes {get;set;} to the ApplicationDbContext class and you will get data access. They don't need to be related. If you need a sample let me know. Hope this helps.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.