How to prevent updates to identity column in Postgres database using Npgsql provider?

0

I have a .NET Core 2.2 api using a Postgres database via the Npgsql Entity Framework provider. I've defined a column as an identity column (OrderNumber) using UseNpgsqlIdentityAlwaysColumn() on the model builder. This all works fine until I try and update an entity. At this point I get the exception:

- InnerException    {Npgsql.PostgresException (0x80004005): 428C9: column "OrderNumber" can only be updated to DEFAULT

The value of the OrderNumber column wasn't changed. Is there a way to tell Npgsql not to try and update that column?

My entity property is defined as:

/// <summary>
/// Unique order number generated by the system for this request
/// </summary>
public int OrderNumber { get; set; }

The model builder definition is:

// Additional auto-increment columns
builder.Entity<DeliveryRequest>().Property(e => e.OrderNumber).UseNpgsqlIdentityAlwaysColumn();

If it helps, I'm using Npgsql.EntityFrameworkCore.PostgreSQL 2.2.4

postgresql
entity-framework
npgsql
asked on Stack Overflow Feb 28, 2020 by Jason

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0