Dapper materializing to a Tuple
Frankly, it's just not supported the way the tuples work. Dapper's deserializer maps column values with constructor parameters or properties/fields by name in the object's type. (Source if you can understand the generated IL).
ValueTuples on the other hand still only have property names corresponding to items in the tuple (Item1
, Item2
, etc.) but uses compiler/ide magic to make them accessible by other names. So StyleId
or StyleCode
will not be actual property names, they're just aliases for Item1
and Item2
respectively.
You'll either have to wait for the team to add in explicit support for ValueTuples or use the expected property names in your query.
var query = $@" SELECT
ST.style_id as Item1, ST.style_code as Item2
...
...";
Looks like they added this a few months ago. Here's an example usage from the tests:
[Fact]
public void TupleReturnValue_Works_NamesIgnored()
{
var val = connection.QuerySingle<(int id, string name)>("select 42 as [Item2], 'Fred' as [Item1]");
Assert.Equal(42, val.id);
Assert.Equal("Fred", val.name);
}