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

ArgumentOutOfRangeException when trying to use identity with a value converter #1596

Closed
sawich opened this issue Dec 2, 2020 · 2 comments · Fixed by #1597
Closed

ArgumentOutOfRangeException when trying to use identity with a value converter #1596

sawich opened this issue Dec 2, 2020 · 2 comments · Fixed by #1597
Assignees
Labels
bug Something isn't working
Milestone

Comments

@sawich
Copy link

sawich commented Dec 2, 2020

[Table("account")]
public class AccountModel
{
    [Required, Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public uint Id { get; set; }

    [Required]
    [MaxLength(24)]
    public string Nickname { get; set; }

    [Required]
    [MaxLength(64)]
    public byte[] Password { get; set; }

    [Required]
    [Column(TypeName = "CHAR(18)")]
    public string Mac { get; set; } = "00-00-00-00-00-00";
}
public class MigrationContext : DbContext
{
    public DbSet<AccountModel> Account { get; set; }
}
PM> add-migration Initial -Project SetupDatabase -Context MigrationContext
Build started...
Build succeeded.
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
   at Npgsql.EntityFrameworkCore.PostgreSQL.Design.Internal.NpgsqlAnnotationCodeGenerator.GenerateValueGenerationStrategy(IDictionary`2 annotations, Boolean onModel)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Design.Internal.NpgsqlAnnotationCodeGenerator.GenerateFluentApiCalls(IProperty property, IDictionary`2 annotations)
   at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GeneratePropertyAnnotations(IProperty property, IndentedStringBuilder stringBuilder)
   at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateProperty(String builderName, IProperty property, IndentedStringBuilder stringBuilder)
   at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateProperties(String builderName, IEnumerable`1 properties, IndentedStringBuilder stringBuilder)
   at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateEntityType(String builderName, IEntityType entityType, IndentedStringBuilder stringBuilder)
   at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateEntityTypes(String builderName, IReadOnlyList`1 entityTypes, IndentedStringBuilder stringBuilder)
   at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGenerator.GenerateMetadata(String migrationNamespace, Type contextType, String migrationName, String migrationId, IModel targetModel)
   at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Specified argument was out of the range of valid values.
<TargetFramework>net5.0</TargetFramework>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0" />
@roji roji self-assigned this Dec 2, 2020
@roji roji added the bug Something isn't working label Dec 2, 2020
@roji roji added this to the 5.0.1 milestone Dec 2, 2020
@roji
Copy link
Member

roji commented Dec 2, 2020

Duplicate of dotnet/efcore#11970

@roji roji marked this as a duplicate of dotnet/efcore#11970 Dec 2, 2020
@roji
Copy link
Member

roji commented Dec 2, 2020

@sawich the problem is that your Id property is a uint, which isn't supported as a native type in PostgreSQL (or any other standard relational database). EF Core does support uint by automatically setting up a value converter, but that isn't compatible with making it an identity column (dotnet/efcore#11970 tracks that).

However, am going to fix the exception coming out.

@roji roji changed the title ArgumentOutOfRangeException ArgumentOutOfRangeException when trying to use identity with a value converter Dec 2, 2020
roji added a commit to roji/efcore.pg that referenced this issue Dec 2, 2020
@roji roji closed this as completed in #1597 Dec 2, 2020
roji added a commit that referenced this issue Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants