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"
    .AsSql()
    .ToList<Person>();

or:
"SELECT * FROM Persons"
    .AsSql()
    .ToList(new {LastName = "", FirstName = ""});
... and return a `DataTable`
.ToDataTable
"SELECT * FROM Persons"
    .AsSql()
    .ToDataTable();
... and immediately iterate over the results without storing them in memory
.WithRows
"SELECT * FROM Persons"
    .AsSql()
    .WithRows(
      row => Console.WriteLine(row["LastName"])
    );
Clone this wiki locally