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

Error compiling optimized DbContext with concurrency token on 8.0 #2992

Closed
isaac-ferrer-tmt opened this issue Nov 27, 2023 · 2 comments · Fixed by #3030
Closed

Error compiling optimized DbContext with concurrency token on 8.0 #2992

isaac-ferrer-tmt opened this issue Nov 27, 2023 · 2 comments · Fixed by #3030
Assignees
Labels
bug Something isn't working
Milestone

Comments

@isaac-ferrer-tmt
Copy link

I have some entities with a uint concurrency token, mapped to the xmin system column, for example:

    public class SomeEntity
    {
        public int Id { get; set; }

        [Timestamp]
        public uint Version { get; set; }
    }

I have upgraded to 8.0. When I run Optimize-DbContext to compile the context, I get the following exception:

System.InvalidOperationException: The type mapping used is incompatible with a compiled model. The mapping type must have a 'public static readonly NpgsqlUIntTypeMapping NpgsqlUIntTypeMapping.Default' property.
   at Microsoft.EntityFrameworkCore.Design.Internal.CSharpRuntimeAnnotationCodeGenerator.CreateDefaultTypeMapping(CoreTypeMapping typeMapping, CSharpRuntimeAnnotationCodeGeneratorParameters parameters)
   at Microsoft.EntityFrameworkCore.Design.Internal.RelationalCSharpRuntimeAnnotationCodeGenerator.Create(CoreTypeMapping typeMapping, CSharpRuntimeAnnotationCodeGeneratorParameters parameters, ValueComparer valueComparer, ValueComparer keyValueComparer, ValueComparer providerValueComparer)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Design.Internal.NpgsqlCSharpRuntimeAnnotationCodeGenerator.Create(CoreTypeMapping typeMapping, CSharpRuntimeAnnotationCodeGeneratorParameters parameters, ValueComparer valueComparer, ValueComparer keyValueComparer, ValueComparer providerValueComparer)
   at Microsoft.EntityFrameworkCore.Design.Internal.ICSharpRuntimeAnnotationCodeGenerator.Create(CoreTypeMapping typeMapping, IProperty property, CSharpRuntimeAnnotationCodeGeneratorParameters parameters)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGenerator.Create(IProperty property, String variableName, Dictionary`2 propertyVariables, CSharpRuntimeAnnotationCodeGeneratorParameters parameters)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGenerator.Create(IProperty property, Dictionary`2 propertyVariables, CSharpRuntimeAnnotationCodeGeneratorParameters parameters)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGenerator.CreateEntityType(IEntityType entityType, IndentedStringBuilder mainBuilder, IndentedStringBuilder methodBuilder, SortedSet`1 namespaces, String className, Boolean nullable)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGenerator.GenerateEntityType(IEntityType entityType, String namespace, String className, Boolean nullable)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGenerator.GenerateModel(IModel model, CompiledModelCodeGenerationOptions options)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CompiledModelScaffolder.ScaffoldModel(IModel model, String outputDir, CompiledModelCodeGenerationOptions options)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.Optimize(String outputDir, String modelNamespace, String contextTypeName)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OptimizeContextImpl(String outputDir, String modelNamespace, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OptimizeContext.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)

It was working fine on 7.0.

@roji
Copy link
Member

roji commented Nov 27, 2023

Thanks, I'll look at this and fix it fox 8.0.1.

@roji roji added the bug Something isn't working label Nov 27, 2023
@roji roji self-assigned this Nov 27, 2023
@roji roji added this to the 8.0.1 milestone Nov 27, 2023
@springy76
Copy link

springy76 commented Nov 30, 2023

Same problem here but I just don't have any uint anywhere in my models, only int32 and int64.

Of course there was an unseen uint in a mapped record:

public record DatabaseInfoEntity(
	[property: Key, Column("oid", TypeName = "oid")] uint ObjectId,
	[property: Column("datname")] string DbName,
	[property: Column("description")] string? Description)

Removed this one and now a compiled model gets created - but it doesn't compile due to private nested classes being referenced: #2972
(and I can't change the class as it comes from IdentityFramework: property DateTimeOffSet? LockoutEnd in user entity)

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.

3 participants