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#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 35,591 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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.