Skip to content
Zev Spitz edited this page Mar 4, 2019 · 6 revisions
In order to execute a statment... Use this method on `SqlString` Example
... without returning records
.Execute
"UPDATE Persons SET LastName = NULL"
    .AsSql()
    .Execute();
... and return a scalar value `.ToScalar` `"SELECT COUNT(*) FROM Persons".AsSql().ToScalar<int>();`
... and return one or more objects (of a named or anonymous type) `.ToList` `"SELECT * FROM Persons".ToList<Person>();`<br>&nbsp;&nbsp;&nbsp;&nbsp;or<br> `"SELECT * FROM Persons".ToList(new {LastName = "", FirstName = ""});`
... and return a `DataTable` `.ToDataTable` `"SELECT * FROM Persons".AsSql().ToDataTable();`
... and iterate over the results without storing them in memory `.WithRows` `"SELECT * FROM Persons".WithRows(row => Console.WriteLine(row["LastName"]));`

Clone this wiki locally