-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
Marcus Ackre Medina edited this page Jul 20, 2026
·
2 revisions
dotnet add package MarcusMedina.Fluent.Data.SqlRequires .NET 10+
using MarcusMedina.Fluent.Data.Sql;
var sql = new Sql(DatabaseType.PostgreSQL)
.Table("customers")
.Select("id", "name", "email")
.Build();
// SELECT "id", "name", "email" FROM "customers";Select() is optional — omit it (or call it with no arguments) and you get SELECT *.
var sql = new Sql(DatabaseType.PostgreSQL)
.Table("orders")
.Is("status", "pending")
.When("total > 100")
.OrderBy("created_at", asc: false)
.Build();
// SELECT * FROM "orders" WHERE "status" = 'pending' AND total > 100 ORDER BY "created_at" DESC;Sql doesn't take (column, operator, value) triples — each comparison has its own named method (.Is, .IsNot, .Contains, .Between, .In, .IsNull, ...). Use .When(rawCondition) for anything not covered by a named method.
Conditions are joined with AND by default. Call .Or() right before a condition to join it with OR instead:
var sql = new Sql(DatabaseType.PostgreSQL)
.Table("users")
.Is("role", "admin")
.Or().Is("role", "owner")
.Build();
// SELECT * FROM "users" WHERE "role" = 'admin' OR "role" = 'owner';var sql = new Sql(DatabaseType.PostgreSQL)
.Table("orders")
.Join("customers", "orders.customer_id = customers.id")
.OrderBy("orders.created_at", asc: false)
.Limit(10)
.Offset(20)
.Build();The constructor argument controls how table/column names are quoted:
new Sql(DatabaseType.MySQL).Table("users").Build(); // SELECT * FROM `users`;
new Sql(DatabaseType.SqlServer).Table("users").Build(); // SELECT * FROM [users];There is no .Insert(), .Update() or .Delete() — Sql only builds SELECT statements. There is also no static FluentSql entry point; you always start with new Sql(dbType).