-
Notifications
You must be signed in to change notification settings - Fork 302
Tuples
Adam Schroder edited this page Oct 27, 2020
·
3 revisions
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/value-tuples
Native tuples are supported as of v5. Here is an example of how to use them.
var (foo, bar) = db.Single<(string, string)>(@"select 'foo', 'bar'");
Assert.AreEqual(foo, "foo");
Assert.AreEqual(bar, "bar");
You can also do nested tuples as per below.
var data = db.Single<((string foo, int i) first, (string bar, int j) second)>(@"select 'foo', 5, 'bar', 6");
Assert.AreEqual(data.first.foo, "foo");
Assert.AreEqual(data.first.i, 5);
Assert.AreEqual(data.second.bar, "bar");
Assert.AreEqual(data.second.j, 6);
Using tuples for parameters is also supported as below.
var record = (2, "Timmy", 5);
db.Execute("update kids set name = @Item2, age = @Item3 where id = @Item1", record);
Here is the original issue. Thanks to @asztal for the slick contribution.
https://github.com/schotime/NPoco/issues/358