Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. How to refer to the AspNetUser table(which is the default table created upon using AspNetCore.Identity;) in my Job Table in .NET Core 6

How to refer to the AspNetUser table(which is the default table created upon using AspNetCore.Identity;) in my Job Table in .NET Core 6

Scheduled Pinned Locked Moved .NET (Core and Framework)
asp-netcsharpdotnettutorialcareer
2 Posts 2 Posters 9 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 13943370
    wrote on last edited by
    #1

    I have created tables using ASP.NET Core Identity. I need to refer my `AspNetUser` table to my `Job` table. I have created a `CustomIdentity` class which inherits from `IdentityUser`.

    This is my code:

    using Microsoft.AspNetCore.Identity;
    
    namespace InventoryManagement.Models
    {
        public class CustomIdentity :IdentityUser
        {
            public string  IsEngineer { get; set; }
            public string  authpassword { get; set; }
        }
    }
    

    And this is my `DbContext` class for `IdentityDbContext`:

    using Microsoft.AspNetCore.Identity;
    using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
    using Microsoft.EntityFrameworkCore;
    
    namespace InventoryManagement.Models.Data
    {
        public class AuthDbContext : IdentityDbContext
        {
            public AuthDbContext(DbContextOptions options) :base(options)
            {
            }
        }
    }
    

    `ASPNETUser` table got created and I am able to insert values into it using `UserManager` to register users. I need to refer this user in my Job table. And here is my code for `Jobdbcontext` where I declare all my other tables:

    using Microsoft.EntityFrameworkCore;
    
    namespace InventoryManagement.Models.Data
    {
        public class JobDBcontext : DbContext
        {
           public JobDBcontext(DbContextOptions options) : base(options) 
           {
           }
    
           public DbSet Jobs { get; set; }
           public DbSet Customers { get; set; }
           public DbSet Jobtype { get; set; }
           public DbSet Manufacturingbay { get; set; }
           public DbSet Projectcategory { get; set; }
           public DbSet Currency { get; set; }
           public DbSet ItemCategory { get; set; }
           public DbSet ItemBudget { get; set; }
           public DbSet ItemSubcategory { get; set; }
           public DbSet ItemMaster { get; set; }
           public DbSet Bom { get; set; }
           public DbSet Test { get; set; }
           public DbSet UomMaster { get; set; }
           public DbSet PR { get; set; }
           public DbSet PRDetails { get; set; }
           public DbSet Supplier { get; set; }
           public DbSet Purchase { get; set; }
           public DbSet PurchaseDetails { get; set; }
    
    Richard DeemingR 1 Reply Last reply
    0
    • U User 13943370

      I have created tables using ASP.NET Core Identity. I need to refer my `AspNetUser` table to my `Job` table. I have created a `CustomIdentity` class which inherits from `IdentityUser`.

      This is my code:

      using Microsoft.AspNetCore.Identity;
      
      namespace InventoryManagement.Models
      {
          public class CustomIdentity :IdentityUser
          {
              public string  IsEngineer { get; set; }
              public string  authpassword { get; set; }
          }
      }
      

      And this is my `DbContext` class for `IdentityDbContext`:

      using Microsoft.AspNetCore.Identity;
      using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
      using Microsoft.EntityFrameworkCore;
      
      namespace InventoryManagement.Models.Data
      {
          public class AuthDbContext : IdentityDbContext
          {
              public AuthDbContext(DbContextOptions options) :base(options)
              {
              }
          }
      }
      

      `ASPNETUser` table got created and I am able to insert values into it using `UserManager` to register users. I need to refer this user in my Job table. And here is my code for `Jobdbcontext` where I declare all my other tables:

      using Microsoft.EntityFrameworkCore;
      
      namespace InventoryManagement.Models.Data
      {
          public class JobDBcontext : DbContext
          {
             public JobDBcontext(DbContextOptions options) : base(options) 
             {
             }
      
             public DbSet Jobs { get; set; }
             public DbSet Customers { get; set; }
             public DbSet Jobtype { get; set; }
             public DbSet Manufacturingbay { get; set; }
             public DbSet Projectcategory { get; set; }
             public DbSet Currency { get; set; }
             public DbSet ItemCategory { get; set; }
             public DbSet ItemBudget { get; set; }
             public DbSet ItemSubcategory { get; set; }
             public DbSet ItemMaster { get; set; }
             public DbSet Bom { get; set; }
             public DbSet Test { get; set; }
             public DbSet UomMaster { get; set; }
             public DbSet PR { get; set; }
             public DbSet PRDetails { get; set; }
             public DbSet Supplier { get; set; }
             public DbSet Purchase { get; set; }
             public DbSet PurchaseDetails { get; set; }
      
      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Navigation properties cannot span multiple DbContext types. If you want an entity type in one context to map to the same table as a type in a different context, then you will need to use the OnModelCreating method to explicitly map it to the correct table. You may also need to exclude it from migrations. There's a good example in this blog post for EF Core 5 RC1: Announcing Entity Framework Core (EFCore) 5.0 RC1 - .NET Blog[^]


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups