-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Zev Spitz edited this page Mar 4, 2019
·
11 revisions
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.)
Then, you can execute multiple SQL statements:
-
Wrap the string containing the SQL statement (or other provider-specific
CommandText
) in anSqlString
(either using theAsSql
extension method, or theSqlString
constructor).- Optionally, pass in the
System.Data.CommandType
- Optionally, pass in one or more objects which will be used to construct parameters
- Optionally, pass in the
// using StringAsSql
List<Person> persons = "SELECT * FROM Persons WHERE LastName = @last"
.AsSql(new {last = "Smith"})
.ToList<Person>();