{"action":"created","issue":{"url":"https://api.github.com/repos/StackExchange/Dapper/issues/735","repository_url":"https://api.github.com/repos/StackExchange/Dapper","labels_url":"https://api.github.com/repos/StackExchange/Dapper/issues/735/labels{/name}","comments_url":"https://api.github.com/repos/StackExchange/Dapper/issues/735/comments","events_url":"https://api.github.com/repos/StackExchange/Dapper/issues/735/events","html_url":"https://github.com/StackExchange/Dapper/issues/735","id":219966183,"number":735,"title":"[Feature Request] Allow materializing a query into a ValueTuple","user":{"login":"0x53A","id":4236651,"avatar_url":"https://avatars3.githubusercontent.com/u/4236651?v=4","gravatar_id":"","url":"https://api.github.com/users/0x53A","html_url":"https://github.com/0x53A","followers_url":"https://api.github.com/users/0x53A/followers","following_url":"https://api.github.com/users/0x53A/following{/other_user}","gists_url":"https://api.github.com/users/0x53A/gists{/gist_id}","starred_url":"https://api.github.com/users/0x53A/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/0x53A/subscriptions","organizations_url":"https://api.github.com/users/0x53A/orgs","repos_url":"https://api.github.com/users/0x53A/repos","events_url":"https://api.github.com/users/0x53A/events{/privacy}","received_events_url":"https://api.github.com/users/0x53A/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/StackExchange/Dapper/milestones/1","html_url":"https://github.com/StackExchange/Dapper/milestone/1","labels_url":"https://api.github.com/repos/StackExchange/Dapper/milestones/1/labels","id":2283965,"number":1,"title":"v2.0","description":"Dapper v2 release, details here: https://github.com/StackExchange/dapper-dot-net/issues/688","creator":{"login":"NickCraver","id":454813,"avatar_url":"https://avatars2.githubusercontent.com/u/454813?v=4","gravatar_id":"","url":"https://api.github.com/users/NickCraver","html_url":"https://github.com/NickCraver","followers_url":"https://api.github.com/users/NickCraver/followers","following_url":"https://api.github.com/users/NickCraver/following{/other_user}","gists_url":"https://api.github.com/users/NickCraver/gists{/gist_id}","starred_url":"https://api.github.com/users/NickCraver/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NickCraver/subscriptions","organizations_url":"https://api.github.com/users/NickCraver/orgs","repos_url":"https://api.github.com/users/NickCraver/repos","events_url":"https://api.github.com/users/NickCraver/events{/privacy}","received_events_url":"https://api.github.com/users/NickCraver/received_events","type":"User","site_admin":false},"open_issues":37,"closed_issues":4,"state":"open","created_at":"2017-01-28T16:22:21Z","updated_at":"2017-08-21T20:46:35Z","due_on":null,"closed_at":null},"comments":4,"created_at":"2017-04-06T17:03:34Z","updated_at":"2018-03-19T00:53:02Z","closed_at":null,"author_association":"NONE","body":"I would like the following code to work:\r\n\r\n```C#\r\n_con.Query<(int id, int value)>(\"select 1 as id, 2 as value\");\r\n```\r\n\r\nCurrently, this compiles and executes without any errors, but the tuple is empty, both values are 0.\r\n\r\nI think this is because it creates the object using the parameterless ctor, then tries to find settable properties named id and value, which it obviously can't find.\r\n\r\nIt would work, if dapper instead used the (int,int) ctor of ValueTuple.\r\n\r\nMy suggestion would be to bake special knowledge of C# tuples into dapper, special casing ValueTuple and using the second ctor (if it matches), instead of preferring the parameterless ctor.\r\n\r\nThe only breaking change would be, as far as I thought this through, if someone had existing code with\r\n\r\n```C#\r\n_con.Query<(int id, int value)>(\"select 1 as Item2, 2 as Item1\");\r\n```\r\n\r\nWith the existing behaviour, it would create the object using the parameterless ctor, then set Item1 to 2 and Item2 to 1.\r\n\r\nWith the proposed behaviour it would create the object with the (int,int) constructor, passing the values in the order they are returned, and setting Item1 to 1, Item2 to 2.\r\n\r\nAnother downside is that this would create unintuitive behaviour with regard to named return values, ignoring the tuple names and filling the tuple positionally.\r\n\r\nE.g. \r\n\r\n```C#\r\n_con.Query<(int id, int value)>(\"select 1 as value, 2 as id\");\r\n```\r\n\r\nwould return a tuple with id = 1, value = 2.\r\n\r\nI still think that this would be worth it, what do you think?"},"comment":{"url":"https://api.github.com/repos/StackExchange/Dapper/issues/comments/374072616","html_url":"https://github.com/StackExchange/Dapper/issues/735#issuecomment-374072616","issue_url":"https://api.github.com/repos/StackExchange/Dapper/issues/735","id":374072616,"user":{"login":"markdchurchill","id":2646766,"avatar_url":"https://avatars1.githubusercontent.com/u/2646766?v=4","gravatar_id":"","url":"https://api.github.com/users/markdchurchill","html_url":"https://github.com/markdchurchill","followers_url":"https://api.github.com/users/markdchurchill/followers","following_url":"https://api.github.com/users/markdchurchill/following{/other_user}","gists_url":"https://api.github.com/users/markdchurchill/gists{/gist_id}","starred_url":"https://api.github.com/users/markdchurchill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markdchurchill/subscriptions","organizations_url":"https://api.github.com/users/markdchurchill/orgs","repos_url":"https://api.github.com/users/markdchurchill/repos","events_url":"https://api.github.com/users/markdchurchill/events{/privacy}","received_events_url":"https://api.github.com/users/markdchurchill/received_events","type":"User","site_admin":false},"created_at":"2018-03-19T00:53:02Z","updated_at":"2018-03-19T00:53:02Z","author_association":"NONE","body":"https://github.com/StackExchange/Dapper/blob/master/Dapper.Tests/TupleTests.cs\r\n\r\nLooks like this is now supported?"}}
{"actor":{"display_login":"markdchurchill"}}