-
-
Notifications
You must be signed in to change notification settings - Fork 10
3.1. Working with basic type parameters
Vedran Bilopavlović edited this page Mar 26, 2021
·
2 revisions
- Mappings are always by position, not by name.
- All database nulls are automatically converted to
nullwhere applicable. Use nullable types to avoid errors. For exampleDateTime?orbool?.
using System.Linq;
// ...
var name = connection.Read<string>("SELECT CustomerName FROM Customers where CustomerID = 1;").Single();
Console.WriteLine(name); // Alfreds Futterkiste using System.Linq;
// ...
var (name, price) = connection.Read<string, decimal>("SELECT ProductName, Price FROM Products where ProductID = 1;").Single();
Console.WriteLine($"{name.Trim()} has price {price}"); // Chais has price 18.0000foreach(var (name, unit, price) in connection.Read<string, string, decimal>("SELECT ProductName, Unit, Price FROM Products"))
{
Console.WriteLine($"{name.Trim()} has price {price} per {unit}");
}using System.Linq;
//...
var dict = connection.Read<int, string>("SELECT ProductID, ProductName FROM Products").ToDictionary(t => t.Item1, t => t.Item2);
foreach(var (key, value) in dict)
{
Console.WriteLine($"{key} {value.Trim()}");
}