Skip to content

Exception while generating typed ids with value converters #2431

@rmihael

Description

@rmihael

Hi.

I have a problem that is similar to #1439. I want to use strongly typed ids in my project. I configure them with a corresponding ValueConverter and UseHiLo(). Migration is generated without any errors, but any attempt to save a new entity throws an exception:

System.ArgumentException: The 'NpgsqlSequenceValueGeneratorFactory' cannot create a value generator for property 'WeatherForecast.Id'. Only integer properties are supported.
   at Npgsql.EntityFrameworkCore.PostgreSQL.ValueGeneration.Internal.NpgsqlSequenceValueGeneratorFactory.Create(IProperty property, NpgsqlSequenceValueGeneratorState generatorState, INpgsqlRelationalConnection connection, IRawSqlCommandBuilder rawSqlCommandBuilder, IRelationalCommandDiagnosticsLogger commandLogger)
   at Npgsql.EntityFrameworkCore.PostgreSQL.ValueGeneration.Internal.NpgsqlValueGeneratorSelector.Select(IProperty property, IEntityType entityType)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ValueGenerationManager.Generate(InternalEntityEntry entry, Boolean includePrimaryKey)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState entityState, Boolean acceptChanges, Boolean modifyProperties, Nullable`1 forceStateWhenUnknownKey)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.PaintAction(EntityEntryGraphNode`1 node)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph[TState](EntityEntryGraphNode`1 node, Func`2 handleNode)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.AttachGraph(InternalEntityEntry rootEntry, EntityState targetState, EntityState storeGeneratedWithKeySetTargetState, Boolean forceStateWhenUnknownKey)
   at Microsoft.EntityFrameworkCore.DbContext.SetEntityState(InternalEntityEntry entry, EntityState entityState)
   at Microsoft.EntityFrameworkCore.DbContext.SetEntityStates(IEnumerable`1 entities, EntityState entityState)
   at Microsoft.EntityFrameworkCore.DbContext.AttachRange(IEnumerable`1 entities)
   at Microsoft.EntityFrameworkCore.DbContext.AttachRange(Object[] entities)
   at StrongIdProblem.Controllers.WeatherForecastController.Get() in /Users/me/RiderProjects/StrongIdProblem/StrongIdProblem/Controllers/WeatherForecastController.cs:line 36

The problem stays if I use UseIdentityByDefaultColumn instead of UseHiLo.

I made a minimal reproducing project based on the standard ASP.NET Core template application: https://github.com/rmihael/StrongIdProblem.

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