Skip to content

C#7 Tuples (i.e. ValueType) #358

Closed
Closed
@troyji

Description

@troyji

I would like to see NPoco support tuples from the upcoming c# 7 release.

https://github.com/dotnet/roslyn/blob/master/docs/features/tuples.md
https://github.com/dotnet/roslyn/blob/features/tuples/docs/features/ValueTuples.cs

It might look something like this:

(int count, int sum) = db.Single<ValueType<int, int>>("select count(1), sum(val) from values");

and this:

var summary = db.Fetch<ValueType<string,int,int>>("select name, count(1), sum(val) from values group by name");
(string name, int count, int sum) = summary.First();

Might as well add support for the existing Tuple type at the same time since the implementation would be similar.

It might look something like this:

Tuple<int, int> result = db.Single<Tuple<int, int>>("select count(1), sum(val) from values");

and this:

List<Tuple<string, int, int>> summary = db.Fetch<Tuple<string,int,int>>("select name, count(1), sum(val) from values group by name");

Allowing query strings formatting with ITuple would support at least ValueTuple, Tuple, and KeyValuePair.

It might look something like:

var record = (2, "Timmy", 5);
db.Execute("update kids set name = @1, age = @2 where id = @0", record);

and this:

Tuple<int, string, in> record = Tuple.Create(2, "Timmy", 5);
db.Execute("update kids set name = @1, age = @2 where id = @0", record);

and this:

var settings= new Dictionary<string, string>() { { "ItemsPerPage", "10" }, { "ShowLogo", "true" } };
foreach(var setting in settings) db.Execute("update settings set value = @1 where key = @0", setting);

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions