primary key nullable problem

selim esa 1 Reputation point
2022-12-30T16:50:41.31+00:00

Hi friend i have a problem "Unable to track an entity of type 'Customer' because its primary key property 'CustomerId' is null.' I want to see the database from the screen but at that time I am facing such a problem
275110-screenshot-3.png

275053-screenshot-2.png275067-screenshot-1.png

Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2022-12-30T18:41:01.023+00:00

    A primary should not be nullable e.g.

    public partial class CustomersConfiguration : IEntityTypeConfiguration<Customers>  
    {  
        public void Configure(EntityTypeBuilder<Customers> entity)  
        {  
            entity.HasKey(e => e.CustomerIdentifier)  
                .HasName("PK_Customers_1");  
      
            . . .   
            OnConfigurePartial(entity);  
        }  
    }  
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.