Skip to content
Zev Spitz edited this page Mar 4, 2019 · 11 revisions

Basic usage

First, set the global ConnectionFactory property, which will return a new connection on which to execute the SQL statement.

// using static StringAsSql
string connectionString = /* ... */;
ConnectionFactory = () => new OleDbConnection(connectionString);

(You can also reuse the connection, or explicitly pass in the connection for each statment.)

Then, you can execute multiple SQL statements:

  1. Wrap the string containing the SQL statement (or other provider-specific CommandText) in an SqlString (either using the AsSql extension method, or the SqlString constructor).

  2. Call one of the various SqlString methods.

Example

// using StringAsSql
List<Person> persons = "SELECT * FROM Persons WHERE LastName = @last"
    .AsSql(new {last = "Smith"})
    .ToList<Person>();
Clone this wiki locally