Database

Query Configuration

WithSQLCommand sets an arbitrary SQL statement as the command source. WithStoredProcedure sets a stored procedure name to call. WithTableName sets a table name for simple SELECT queries - GPAL generates a basic SELECT automatically. WithRowCount limits the number of rows returned when using WithTableName. WithReadAs, WithCreateAs, WithUpdateAs, and WithDeleteAs set the SQL for each CRUD operation type when all four may be needed on a single database object.

Examples

GPAL Fluent: High-level fluent C# API

//WithTableName is the simplest query option - GPAL generates 'SELECT TOP n * FROM tableName'. Use WithSQLCommand or WithStoredProcedure when you need filtering, joins, or custom column selection.

// the grid is declared, because out var cannot choose between the SaveTo overloads

IGPALGrid<string> products;

IGPALGrid<string> customers;

IGPALGrid<string> orders;


// Query via SQL command

GPAL.Database

.WithConnectionString(connStr)

.WithSQLCommand("SELECT TOP 100 * FROM Products ORDER BY Name")

.ToGPALObject()

.Read

.SaveTo(out products);


// Query via table name (auto-generates SELECT)

GPAL.Database

.WithConnectionString(connStr)

.WithTableName("Customers")

.WithRowCount(500)

.ToGPALObject()

.Read

.SaveTo(out customers);


// Call a stored procedure

GPAL.Database

.WithConnectionString(connStr)

.WithStoredProcedure("usp_GetActiveOrders")

.ToGPALObject()

.Read

.SaveTo(out orders);

💬 Ask GPAL