{"record":{"id":"809020e0b0b4b2b2","repo":"dotnet/efcore","slug":"input-parameter-parameter-of-insert-stored-pro","errorCode":null,"errorMessage":"Input parameter '{parameter}' of insert stored procedure '{sproc}' is mapped to property '{property}' of entity type '{entityType}', but that property is configured with BeforeSaveBehavior '{behavior}', and so cannot be saved on insert.","messagePattern":"Input parameter '(.+?)' of insert stored procedure '(.+?)' is mapped to property '(.+?)' of entity type '(.+?)', but that property is configured with BeforeSaveBehavior '(.+?)', and so cannot be saved on insert\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs","lineNumber":744,"sourceCode":"                            RelationalStrings.StoredProcedureParameterNotFound(\n                                parameter.PropertyName, entityType.DisplayName(), storeObjectIdentifier.DisplayName()));\n                    }\n\n                    if (storeObjectIdentifier.StoreObjectType == StoreObjectType.DeleteStoredProcedure)\n                    {\n                        throw new InvalidOperationException(\n                            RelationalStrings.StoredProcedureCurrentValueParameterOnDelete(\n                                parameter.Name, storeObjectIdentifier.DisplayName()));\n                    }\n\n                    if (parameter.Direction.HasFlag(ParameterDirection.Input))\n                    {\n                        switch (storeObjectIdentifier.StoreObjectType)\n                        {\n                            case StoreObjectType.InsertStoredProcedure:\n                                if (property.GetBeforeSaveBehavior() != PropertySaveBehavior.Save)\n                                {\n                                    throw new InvalidOperationException(\n                                        RelationalStrings.StoredProcedureInputParameterForInsertNonSaveProperty(\n                                            parameter.Name,\n                                            storeObjectIdentifier.DisplayName(),\n                                            parameter.PropertyName,\n                                            entityType.DisplayName(),\n                                            property.GetBeforeSaveBehavior()));\n                                }\n\n                                break;\n\n                            case StoreObjectType.UpdateStoredProcedure:\n                                if (property.GetAfterSaveBehavior() != PropertySaveBehavior.Save)\n                                {\n                                    throw new InvalidOperationException(\n                                        RelationalStrings.StoredProcedureInputParameterForUpdateNonSaveProperty(\n                                            parameter.Name,\n                                            storeObjectIdentifier.DisplayName(),\n                                            parameter.PropertyName,","sourceCodeStart":726,"sourceCodeEnd":762,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L726-L762","documentation":"Thrown when an insert input parameter is mapped to a property whose BeforeSaveBehavior is not Save. Properties that are ignored or throw on insert cannot be persisted during an insert. The validator requires property.GetBeforeSaveBehavior() == PropertySaveBehavior.Save for any insert input parameter.","triggerScenarios":"Mapping a property configured with .BeforeSave(PropertySaveBehavior.Ignore) (or a value generated on add) to an insert input parameter; treating an after-save/computed property as writable on insert.","commonSituations":"Setting BeforeSaveBehavior.Ignore on a property but still binding it as an insert sproc parameter; mismatch between ValueGenerated and parameter mapping.","solutions":["Set the property's BeforeSaveBehavior to Save so it can be written on insert.","Remove the input parameter if the property should not be saved on insert.","If the value is store-generated, use a result column instead of an input parameter."],"exampleFix":"// before\nmodelBuilder.Entity<Blog>().Property(b => b.CreatedAt).Metadata.SetBeforeSaveBehavior(PropertySaveBehavior.Ignore);\nsp.HasParameter(\"CreatedAt\"); // insert input param\n\n// after\nmodelBuilder.Entity<Blog>().Property(b => b.CreatedAt).Metadata.SetBeforeSaveBehavior(PropertySaveBehavior.Save);\nsp.HasParameter(\"CreatedAt\");","handlingStrategy":"validation","validationCode":"foreach (var et in modelBuilder.Model.GetEntityTypes())\n{\n    var ins = et.GetInsertStoredProcedure();\n    if (ins == null) continue;\n    foreach (var p in ins.Parameters.Where(p => p.PropertyName != null && p.ForOriginalValue != true && p.Direction.HasFlag(System.Data.ParameterDirection.Input)))\n    {\n        var prop = et.FindProperty(p.PropertyName);\n        if (prop != null && prop.GetBeforeSaveBehavior() != PropertySaveBehavior.Save)\n            throw new InvalidOperationException($\"{p.Name} maps to non-Save BeforeSaveBehavior property\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try { _ = ctx.Model; } catch (InvalidOperationException ex) when (ex.Message.Contains(\"cannot be saved on insert\")) { /* set BeforeSaveBehavior.Save or remove the param */ }","preventionTips":["Align BeforeSaveBehavior with sproc parameter mapping.","For store-generated values on insert, prefer a result column over an input parameter."],"tags":["ef-core","stored-procedures","parameters","insert","save-behavior","model-validation"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}