{"record":{"id":"6d30b499347db8fb","repo":"dotnet/efcore","slug":"the-property-entitytype-property-has-a-value","errorCode":null,"errorMessage":"The property '{entityType}.{property}' has a value generator configured. Use '{method}' to configure the value generator factory type.","messagePattern":"The property '(.+?)\\.(.+?)' has a value generator configured\\. Use '(.+?)' to configure the value generator factory type\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Scaffolding/Internal/CSharpRuntimeModelCodeGenerator.cs","lineNumber":1088,"sourceCode":"                    .Append(_code.UnknownLiteral(providerValue))\n                    .AppendLine(\");\")\n                    .AppendLine();\n            }\n        }\n    }\n\n    private void Create(\n        IProperty property,\n        Dictionary<MemberInfo, QualifiedName>? memberAccessReplacements,\n        CSharpRuntimeAnnotationCodeGeneratorParameters parameters)\n    {\n        var variableName = _code.Identifier(property.Name, property, parameters.ScopeObjects, capitalize: false);\n\n        var valueGeneratorFactoryType = (Type?)property[CoreAnnotationNames.ValueGeneratorFactoryType];\n        if (valueGeneratorFactoryType == null\n            && property.GetValueGeneratorFactory() != null)\n        {\n            throw new InvalidOperationException(\n                DesignStrings.CompiledModelValueGenerator(\n                    property.DeclaringType.ShortName(), property.Name, nameof(PropertyBuilder.HasValueGeneratorFactory)));\n        }\n\n        var mainBuilder = parameters.MainBuilder;\n        mainBuilder\n            .Append(\"var \").Append(variableName).Append(\" = \").Append(parameters.TargetName).AppendLine(\".AddProperty(\")\n            .IncrementIndent()\n            .Append(_code.Literal(property.Name));\n\n        GeneratePropertyBaseParameters(property, parameters);\n\n        if (property.IsNullable)\n        {\n            mainBuilder.AppendLine(\",\")\n                .Append(\"nullable: \")\n                .Append(_code.Literal(true));\n        }","sourceCodeStart":1070,"sourceCodeEnd":1106,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Scaffolding/Internal/CSharpRuntimeModelCodeGenerator.cs#L1070-L1106","documentation":"Thrown by CSharpRuntimeModelCodeGenerator when a property has a value generator instance configured (GetValueGeneratorFactory() is non-null) but no ValueGeneratorFactoryType annotation. Compiled models can only persist a factory type (so it can be reconstructed), not an arbitrary generator instance, so an instance-only configuration is refused; the message directs you to use HasValueGeneratorFactory instead.","triggerScenarios":"Configuring a property with HasValueGenerator(...) (an instance) rather than HasValueGeneratorFactory(...) (a type), then generating a compiled model.","commonSituations":"Custom value generators registered as instances; migrating value-generator configuration to the compiled-model workflow.","solutions":["Switch from HasValueGenerator<TInstance>() to HasValueGeneratorFactory<TFactory>() so the compiled model can store the type.","Provide a ValueGenerator factory type that the compiled model can serialize.","If an instance is truly required, accept that the compiled model cannot encode it and configure it at runtime."],"exampleFix":"// before\nmodelBuilder.Entity<E>().Property(p => p.Id).HasValueGenerator<MyGenerator>();\n// after\nmodelBuilder.Entity<E>().Property(p => p.Id).HasValueGeneratorFactory<MyGeneratorFactory>();","handlingStrategy":"validation","validationCode":"// Detect instance-based value generators before compiled-model generation\nforeach (var p in model.GetEntityTypes().SelectMany(e => e.GetProperties()))\n{\n    var factoryType = (Type?)p[CoreAnnotationNames.ValueGeneratorFactoryType];\n    if (factoryType is null && p.GetValueGeneratorFactory() is not null)\n        Console.WriteLine($\"{p.DeclaringType}.{p.Name} uses an instance generator; switch to HasValueGeneratorFactory.\");\n}","typeGuard":null,"tryCatchPattern":"try { Optimize(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"value generator\"))\n{ /* switch to HasValueGeneratorFactory<TFactory> then regenerate */ }","preventionTips":["Use HasValueGeneratorFactory<TFactory> instead of HasValueGenerator<TInstance> when targeting compiled models.","Audit value-generator configuration before running optimize.","Document that compiled models can only serialize generator factory types, not instances."],"tags":["compiled-model","value-generator","entity-types","scaffolding"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}