Skip to content

Column with setting generated by default as identity not auto-incrementing #203

@chinyik94

Description

@chinyik94

Hi, I'm having an issue where EF6 context.Entity.Add(entity) not auto-incrementing its Primary Key after inserting the data.
I'm currently using the following nuget packages in a .NET Framework 4.8 project:

  • EntityFramework6.Npgsql v6.4.3
  • Npgsql v4.1.3

\d "ErrorLog":

image

Minimum reproduceable repo can refer to: https://github.com/chinyik94/NpgsqlSample
Entity model file:

'------------------------------------------------------------------------------
' <auto-generated>
'     This code was generated from a template.
'
'     Manual changes to this file may cause unexpected behavior in your application.
'     Manual changes to this file will be overwritten if the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------

Imports System
Imports System.Collections.Generic

Partial Public Class ErrorLog
    Public Property ErrorLogId As Integer
    Public Property ErrorDetails As String
    Public Property DateCreated As Date

End Class

Adding new data to entity:

        Using context As New C4WX1Entities
            Dim errorLog As New ErrorLog

            errorLog.ErrorDetails = "Test Error"
            errorLog.DateCreated = Now()
            context.ErrorLog.Add(errorLog)

            context.SaveChanges()
        End Using

Expected:
ErrorLogId = 1, ErrorDetails = "Test Error", DateCreated = Now

Actual:
ErrorLogId = 0, ErrorDetails = "Test Error", DateCreated = Now

I also tried using negative ID as recommended in npgsql/efcore.pg#1391, but the Primary Key inserted is -1 instead if I provide the value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions