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

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

Open
chinyik94 opened this issue Dec 10, 2024 · 1 comment

Comments

@chinyik94
Copy link

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.

@roji
Copy link
Member

roji commented Dec 10, 2024

@chinyik94 just to make sure you know that the EF6 provider is archived, and there's nobody regularly answering questions here. Someone from the community may be able to help though.

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

2 participants