Click here to Skip to main content
15,946,320 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
PinnedHOW TO ANSWER A QUESTION Pin
Chris Maunder16-Jul-09 3:09
cofounderChris Maunder16-Jul-09 3:09 
PinnedHow to get an answer to your question Pin
Chris Maunder16-Jul-09 3:05
cofounderChris Maunder16-Jul-09 3:05 
QuestionRemote debugging on Raspberry Pi in Visual Studio Code. Pin
Jerry Walter 202422-Apr-24 15:02
Jerry Walter 202422-Apr-24 15:02 
AnswerRe: Remote debugging on Raspberry Pi in Visual Studio Code. Pin
jschell23-Apr-24 14:13
jschell23-Apr-24 14:13 
Questionhi please help me with a filter on view Pin
Chrayet Mahdi9-Mar-24 6:13
Chrayet Mahdi9-Mar-24 6:13 
AnswerRe: hi please help me with a filter on view Pin
jschell12-Mar-24 14:46
jschell12-Mar-24 14:46 
AnswerRe: hi please help me with a filter on view Pin
Andre Oosthuizen14-Mar-24 6:36
mveAndre Oosthuizen14-Mar-24 6:36 
QuestionAdvice on a product to convert PDF to TIFF or JPEG. Pin
PhilMcGahan2-Mar-24 3:00
PhilMcGahan2-Mar-24 3:00 
AnswerRe: Advice on a product to convert PDF to TIFF or JPEG. Pin
jschell6-Mar-24 12:12
jschell6-Mar-24 12:12 
AnswerRe: Advice on a product to convert PDF to TIFF or JPEG. Pin
TNCaver14-Mar-24 7:01
TNCaver14-Mar-24 7:01 
QuestionC#, WPF project Pin
Member 1621198528-Feb-24 2:50
Member 1621198528-Feb-24 2:50 
AnswerRe: C#, WPF project Pin
Richard Deeming28-Feb-24 3:22
mveRichard Deeming28-Feb-24 3:22 
AnswerRe: C#, WPF project Pin
Gerry Schmitz28-Feb-24 7:04
mveGerry Schmitz28-Feb-24 7:04 
AnswerRe: C#, WPF project Pin
jschell28-Feb-24 12:22
jschell28-Feb-24 12:22 
RantForm Cancel Property paired up with Button DialogResult Property is Diabolical! Pin
Brian L Hughes27-Feb-24 17:04
Brian L Hughes27-Feb-24 17:04 
QuestionGantt chart for management app c# Windows Forms Pin
Ionut Ciocan20-Feb-24 12:17
Ionut Ciocan20-Feb-24 12:17 
AnswerRe: Gantt chart for management app c# Windows Forms Pin
jeron120-Feb-24 12:33
jeron120-Feb-24 12:33 
QuestionVisual Studio 2022 and Angular Language Service Pin
Z.C.M.8-Feb-24 11:19
professionalZ.C.M.8-Feb-24 11:19 
AnswerRe: Visual Studio 2022 and Angular Language Service Pin
Gerry Schmitz9-Feb-24 9:58
mveGerry Schmitz9-Feb-24 9:58 
GeneralRe: Visual Studio 2022 and Angular Language Service Pin
jschell9-Feb-24 12:08
jschell9-Feb-24 12:08 
GeneralRe: Visual Studio 2022 and Angular Language Service Pin
Gerry Schmitz10-Feb-24 9:34
mveGerry Schmitz10-Feb-24 9:34 
GeneralRe: Visual Studio 2022 and Angular Language Service Pin
Z.C.M.12-Feb-24 3:30
professionalZ.C.M.12-Feb-24 3:30 
GeneralRe: Visual Studio 2022 and Angular Language Service Pin
Gerry Schmitz12-Feb-24 7:51
mveGerry Schmitz12-Feb-24 7:51 
AnswerRe: Visual Studio 2022 and Angular Language Service Pin
Bohdan Stupak4-Mar-24 23:09
professionalBohdan Stupak4-Mar-24 23:09 
QuestionHow to refer to the AspNetUser table(which is the default table created upon using AspNetCore.Identity;) in my Job Table in .NET Core 6 Pin
Member 139757394-Feb-24 4:53
Member 139757394-Feb-24 4:53 
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<CustomIdentity>
        {
            public AuthDbContext(DbContextOptions<AuthDbContext> 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<JobDBcontext> options) : base(options) 
           {
           }

           public DbSet<Job> Jobs { get; set; }
           public DbSet<Customer> Customers { get; set; }
           public DbSet<JobType> Jobtype { get; set; }
           public DbSet<ManufacturingBay> Manufacturingbay { get; set; }
           public DbSet<ProjectCategory> Projectcategory { get; set; }
           public DbSet<Currency> Currency { get; set; }
           public DbSet<Category> ItemCategory { get; set; }
           public DbSet<Budget> ItemBudget { get; set; }
           public DbSet<SubCategory> ItemSubcategory { get; set; }
           public DbSet<ItemMaster> ItemMaster { get; set; }
           public DbSet<Bom> Bom { get; set; }
           public DbSet<Test> Test { get; set; }
           public DbSet<UOM> UomMaster { get; set; }
           public DbSet<PR> PR { get; set; }
           public DbSet<PRDetails> PRDetails { get; set; }
           public DbSet<Supplier> Supplier { get; set; }
           public DbSet<Purchase> Purchase { get; set; }
           public DbSet<PurchaseDetails> PurchaseDetails { get; set; }

           protected override void OnModelCreating(ModelBuilder modelBuilder)
           {
                if (modelBuilder == null)
                {
                    throw new ArgumentNullException(nameof(modelBuilder));
                }

                modelBuilder.Entity<JobType>().HasKey(jt => jt.Jobtypeid);
                modelBuilder.Entity<ProjectCategory>().HasKey(jt => jt.Pid);
                modelBuilder.Entity<Currency>().HasKey(jt => jt.cid);
                modelBuilder.Entity<Bom>().HasKey(jt => jt.BID);

                modelBuilder.Entity<Budget>()
                            .HasKey(b => b.ID);

                modelBuilder.Entity<Category>()
                    .HasKey(c => c.CategoryId);
                modelBuilder.Entity<SubCategory>()
                    .HasKey(s => s.SubCategoryId);
                 modelBuilder.Entity<ItemMaster>()
                    .HasKey(i => i.itemid);
                modelBuilder.Entity<UOM>()
                  .HasKey(i => i.uid);
                // Configure relationships
                modelBuilder.Entity<Budget>()
              .HasMany(b => b.categories)
              .WithOne(c => c.Budget)
              .OnDelete(DeleteBehavior.Cascade);
                modelBuilder.Entity<Category>()
                    .HasMany(c => c.SubCategories)
                    .WithOne(i => i.category)
                     .OnDelete(DeleteBehavior.Cascade);

                //  modelBuilder.Entity<SubCategory>()
                //      .HasMany(s => s.ItemMasters)
                //      .WithOne(i => i.subcategory)
                //      .HasForeignKey(i => i.category)
                //      .OnDelete(DeleteBehavior.Cascade);

                // Other configurations for your entity can go here

                //modelBuilder.Entity<PR>()
                //              .HasKey(p => p.Prid);

                //modelBuilder.Entity<PRDetails>()
                //    .HasKey(d => d.Prtblid);

                //modelBuilder.Entity<PRDetails>()
                //    .Property(d => d.Prid);  // Ensure Prid property is properly configured, adjust as needed

                //modelBuilder.Entity<PRDetails>()
                //    .HasOne(d => d.PR)
                //    .WithMany(p => p.PRDetails)
                //    .HasForeignKey(d => d.Prid)
                //    .OnDelete(DeleteBehavior.Restrict); // or specify other actions as needed

                // Additional configurations for other entities and relationships

                modelBuilder.Entity<PR>()
                  .HasKey(p => p.Prid);

                modelBuilder.Entity<PRDetails>()
                    .HasKey(d => d.PrDetailId);

                modelBuilder.Entity<PRDetails>()
                    .HasOne(d => d.PR)
                    .WithMany(p => p.PRDetails)
                    .HasForeignKey(d => d.Prid)
                    .OnDelete(DeleteBehavior.NoAction); // Change this to NoAction or other options

                modelBuilder.Entity<PRDetails>()
                    .HasOne(d => d.Bom)
                    .WithMany() // Assuming Bom doesn't have a navigation property back to PRDetails
                    .HasForeignKey(d => d.Bomid)
                    .OnDelete(DeleteBehavior.Cascade);

                base.OnModelCreating(modelBuilder);

                modelBuilder.Entity<Purchase>()
                 .HasKey(p => p.POID);

                modelBuilder.Entity<PurchaseDetails>()
                    .HasKey(d => d.potblid);

                modelBuilder.Entity<PurchaseDetails>()
                    .HasOne(d => d.Purchase)
                    .WithMany(p => p.PurchaseDetails)
                    .HasForeignKey(d => d.POID)
                    .OnDelete(DeleteBehavior.NoAction); // Change this to NoAction or other options

                modelBuilder.Entity<PurchaseDetails>()
                    .HasOne(d => d.prdetails)
                    .WithMany() // Assuming Bom doesn't have a navigation property back to PRDetails
                    .HasForeignKey(d => d.PrDetailId)
                    .OnDelete(DeleteBehavior.Cascade);
                base.OnModelCreating(modelBuilder);
                modelBuilder.Entity<Job>()
               .HasOne(j => j.User)
               .WithMany()
               .HasForeignKey(j => j.UserId)
               .IsRequired();
            }
        }
    }

This is my `Job` model where I am referencing my CustomIdentity.

    namespace InventoryManagement.Models
    {
        public class Job
        {
            public int Jobsequenceno { get; set; }
            public int JobId { get; set; }

            public string JobName { get; set; } 
      
            public int Qty { get; set; }
            public Customer Customer { get; set; }

            public DateTime JobDate { get; set; }
            public JobType JobType { get; set; }

            public ManufacturingBay ManufacturingBay { get; set; }
            public ProjectCategory Projectcategory { get; set; }
            public Currency currency { get; set; }
            public Double JobRate { get; set; }
            public Double Ordervalue { get; set; }
            public Double Ordervalueinbasecurrency { get; set; }

            public string  JobDescription { get; set; }
            public string Paymentterms { get; set; }
            public string Deliveryterms { get; set; }

            public string UserId { get; set; }
            public CustomIdentity User { get; set; }
        }
    }

Upon running migrations of 2 `DbContext` tables are created ..but upon running migration of JobDBcontext another class called customidentity is created which has exactly same column like my ASPNetUser and my job table is referring to that class.

    ALTER TABLE [dbo].[Jobs] WITH CHECK 
        ADD CONSTRAINT [FK_Jobs_CustomIdentity_UserId] 
            FOREIGN KEY([UserId]) REFERENCES [dbo].[CustomIdentity] ([Id])
            ON DELETE CASCADE  

I want the Job  table to refer to the `ASPNETUSER` table which is having value instead of this CustomIdentity table.... I am able to insert user data to Job table.but upon listing job I am referring to `CustomIdentity` which is showing null..

     [HttpGet("List")]
     public async Task<IActionResult> List()
     {
         // use dbContext to read the tags
         var Joblist = await jobdbcontext.Jobs.Include(j => j.Customer).Include(j => j.JobType).Include(j => j.ManufacturingBay).
             Include(j => j.Projectcategory).
              Include(j => j.CustomIdentity).
              Include(j => j.currency).
         Include(j =>j.User).
             ToListAsync();
         return View(Joblist);
     }

How to resolve this?so that my Job table will refer ASPNetUser table which is having value instead of CustomIdentity table.CustomIdentity model is created to add extra columns in my ASPNetUser table.I am new to this ..can anyone help on this ?

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.