Fast.SqlSugar
Public members, parameters, returns, and exceptions
Targets: net8.0;net9.0;net10.0.
Contract and constraints
Scoped repositories, entity auditing, connection selection and paging. AddSqlSugar() defaults to ConnectionSettings. Register or discover an ISqlSugarEntityHandler implementation; the client factory requires it. Its constructor must not depend on ISqlSugarClient and create a cycle. The static connection options read by the factory are not automatically post-configured: supply complete configuration or call PostConfigure explicitly in the callback before overriding values. Repository queries return counts, existence, entities or lists; missing single results require null handling even where annotations are absent. Writes, logical deletes and schema utilities perform real database operations. Calls are not automatically grouped into a transaction. PagedInput defaults to PageIndex=1, PageSize=20 and EnablePaged=true; MaxNotPageSize defaults to 10000. Assign unique Snowflake worker IDs per instance. The examples below query existing tables without creating a schema or writing data.
Installation and examples
Install the package
dotnet add package Fast.SqlSugarExample 1
using Fast.SqlSugar;
public static class PagingDefaults
{
public static PagedInput FirstPage() => new() { PageIndex = 1, PageSize = 20 };
}Example 2
using Fast.SqlSugar;
using SqlSugar;
[SugarTable("CatalogItem")]
public sealed class CatalogItem
{
[SugarColumn(IsPrimaryKey = true)]
public long Id { get; set; }
public string Name { get; set; } = "";
}
public sealed class CatalogReader(ISqlSugarRepository<CatalogItem> repository)
{
public Task<int> CountAsync(string name) =>
repository.CountAsync(item => item.Name == name);
public Task<bool> ExistsAsync(long id) =>
repository.AnyAsync(item => item.Id == id);
public Task<CatalogItem> FindAsync(long id) =>
repository.SingleOrDefaultAsync((object)id);
}Web-host examples belong in a consumer project using Microsoft.NET.Sdk.Web and a supported .NET target. IaaS examples can be used in an ordinary class library. Registration precedes builder.Build(); configure middleware and endpoints before app.Run(). Samples retain their original code and comments. No host, external service, database operation or client generator was run, and these snippets have not been compiled in this update.
Source reference
Non-paged limits
Non-paged queries fetch at most MaxNotPageSize + 1 rows to distinguish exactly N from more than N. Exactly N is allowed; N+1 is rejected in both sync and async paths. The configured limit must be 1 through int.MaxValue-1. Paging safeguards remain in place.
