Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nick5454 opened this issue Jun 18, 2021 · 1 comment
Assignees

Comments

@nick5454
Copy link

nick5454 commented Jun 18, 2021

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.

@sjh37
Copy link
Owner

sjh37 commented Jun 18, 2021

Thanks @nick5454

@sjh37 sjh37 self-assigned this Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants