{"record":{"id":"75017b70f5700cae","repo":"dotnet/efcore","slug":"the-specified-minbatchsize-value-value-is-no","errorCode":null,"errorMessage":"The specified 'MinBatchSize' value '{value}' is not valid. It must be a positive number.","messagePattern":"The specified 'MinBatchSize' value '(.+?)' is not valid\\. It must be a positive number\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs","lineNumber":225,"sourceCode":"    /// <summary>\n    ///     The minimum number of statements that are needed for a multi-statement command sent to the database\n    ///     during <see cref=\"DbContext.SaveChanges()\" /> or <see langword=\"null\" /> if none has been set.\n    /// </summary>\n    public virtual int? MinBatchSize\n        => _minBatchSize;\n\n    /// <summary>\n    ///     Creates a new instance with all options the same as for this instance, but with the given option changed.\n    ///     It is unusual to call this method directly. Instead use <see cref=\"DbContextOptionsBuilder\" />.\n    /// </summary>\n    /// <param name=\"minBatchSize\">The option to change.</param>\n    /// <returns>A new instance with the option changed.</returns>\n    public virtual RelationalOptionsExtension WithMinBatchSize(int? minBatchSize)\n    {\n        if (minBatchSize.HasValue\n            && minBatchSize <= 0)\n        {\n            throw new InvalidOperationException(RelationalStrings.InvalidMinBatchSize(minBatchSize));\n        }\n\n        var clone = Clone();\n\n        clone._minBatchSize = minBatchSize;\n\n        return clone;\n    }\n\n    /// <summary>\n    ///     Indicates whether or not to use relational database semantics when comparing null values. By default,\n    ///     Entity Framework will use C# semantics for null values, and generate SQL to compensate for differences\n    ///     in how the database handles nulls.\n    /// </summary>\n    public virtual bool UseRelationalNulls\n        => _useRelationalNulls;\n\n    /// <summary>","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs#L207-L243","documentation":"RelationalOptionsExtension.WithMinBatchSize requires null (unset) or a value strictly greater than zero; 0 and negatives are rejected. This sets the threshold below which statements are sent individually rather than grouped.","triggerScenarios":"Calling optionsBuilder.MinBatchSize(0) or a negative; computing MinBatchSize from configuration that resolves to 0.","commonSituations":"Confusing MinBatchSize with MaxBatchSize; passing 0 intending 'always batch'; mis-parsed config.","solutions":["Pass a positive int (>= 1), or leave unset / pass null for the provider default.","Validate config and coerce 0/negative to null.","Ensure MinBatchSize <= MaxBatchSize to avoid later provider complaints."],"exampleFix":"// before\noptionsBuilder.UseSqlServer(conn).MinBatchSize(0);\n\n// after\noptionsBuilder.UseSqlServer(conn).MinBatchSize(2); // or omit","handlingStrategy":"validation","validationCode":"static int? SafeMinBatchSize(string? raw)\n    => int.TryParse(raw, out var v) && v > 0 ? v : (int?)null;","typeGuard":"static bool IsValidMinBatchSize(int? value) => value is null || value > 0;","tryCatchPattern":null,"preventionTips":["Pass a positive int or leave unset; 0/negative is invalid.","Ensure MinBatchSize does not exceed MaxBatchSize.","Validate config-derived values centrally."],"tags":["configuration","options","batching","relational"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}