{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs#L207-L243","documentation":"Thrown by RelationalOptionsExtension.WithMinBatchSize(int?) at lines 222-225 when the supplied value is <= 0. MinBatchSize is the threshold below which EF sends statements individually instead of batching them; it must be at least 1.","triggerScenarios":"Calling optionsBuilder.UseSqlServer(connStr, sql => sql.MinBatchSize(0)) or a negative value. Also from misconfigured configuration files or environment variables.","commonSituations":"Reading MinBatchSize from config with a 0 default. Confusing MinBatchSize with MaxBatchSize and setting it to 0 thinking it disables the minimum threshold.","solutions":["Set MinBatchSize to a positive integer (typically 2 or higher; 1 means batch even single statements).","Validate the config value before passing: if (configuredMinBatchSize > 0) sql.MinBatchSize(configuredMinBatchSize);"],"exampleFix":"// before\noptionsBuilder.UseSqlServer(connStr, sql => sql.MinBatchSize(0));\n\n// after\noptionsBuilder.UseSqlServer(connStr, sql => sql.MinBatchSize(4));","handlingStrategy":"validation","validationCode":"var minBatch = configuration.GetValue<int?>(\"MinBatchSize\");\nif (minBatch.HasValue && minBatch <= 0) throw new ArgumentOutOfRangeException(nameof(minBatch), \"MinBatchSize must be > 0\");\noptionsBuilder.UseSqlServer(connStr, sql => { if (minBatch > 0) sql.MinBatchSize(minBatch.Value); });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate min batch size config values are > 0 before passing.","Use a shared helper to validate all integer EF options from configuration."],"tags":["batch-size","configuration","argument-validation"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}