EntityFramework-Reverse-POCO-Generator-UI icon indicating copy to clipboard operation
EntityFramework-Reverse-POCO-Generator-UI copied to clipboard

In EF Core, if a column is an Identity and not the Primary needs metadata added

Open nick5454 opened this issue 4 years ago • 1 comments

When you have a table column that is an Identity column, but not the Primary key. There needs to be a metadata ignore statement.

builder.Property(x => x.Id)
    .HasColumnName(@"Id")
    .HasColumnType("bigint")
    .IsRequired()
    .ValueGeneratedOnAdd()
    .UseIdentityColumn();
            
builder.Property(x => x.Id)
    .Metadata.SetAfterSaveBehavior(Microsoft.EntityFrameworkCore.Metadata.PropertySaveBehavior.Ignore);

The Metadata is needed to avoid saving exceptions, if the column is not in the primary key.

It would be nice to include this in a future release.

nick5454 avatar Jun 18 '21 20:06 nick5454

Thanks @nick5454

sjh37 avatar Jun 18 '21 20:06 sjh37