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

Null RowVersion Violates Not-Null Constraint in PostgreSQL #1

Open
MrEshboboyev opened this issue Dec 20, 2024 · 0 comments
Open

Null RowVersion Violates Not-Null Constraint in PostgreSQL #1

MrEshboboyev opened this issue Dec 20, 2024 · 0 comments

Comments

@MrEshboboyev
Copy link
Owner

Environment Details:

  • .NET SDK Version: 9.0.100
  • dotnet-ef Version: 9.0.0
  • Operating System: Windows 10 x64
  • Database: PostgreSQL

Steps to Reproduce:

  1. Define a BankAccount entity with a RowVersion property for concurrency control.
  2. Configure the RowVersion property using .IsRowVersion().
  3. Attempt to save a BankAccount entity to the PostgreSQL database without initializing RowVersion.

Expected Behavior:
Entity should be saved with the RowVersion property automatically managed by Entity Framework Core.

Actual Behavior:
Error message: Npgsql.PostgresException (0x80004005): 23502: null value in column "RowVersion" of relation "BankAccounts" violates not-null constraint.

Full Error Message:

Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details.
 ---> Npgsql.PostgresException (0x80004005): 23502: null value in column "RowVersion" of relation "BankAccounts" violates not-null constraint

Code Examples:
Entity Configuration:

public class BankAccount
{
    public int Id { get; set; }
    public decimal Balance { get; set; }
    public byte[] RowVersion { get; set; }
}

DbContext Configuration:

public class ConcurrencyControlDbContext : DbContext
{
    public DbSet<BankAccount> BankAccounts { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<BankAccount>()
                    .Property(b => b.RowVersion)
                    .IsRowVersion();
    }
}

Additional Context:

  • Verified that the RowVersion property is configured for concurrency control using .IsRowVersion().
  • Encountering this issue even after ensuring the RowVersion property is properly defined in the entity model and DbContext.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant