Dupper materializing into a tuple

I need to return a list from dapper with a new tuple in C # 7.

public static List<(int StyleId, decimal StyleCode)> GetOnlyServices() { var query = $@ " SELECT ST.style_id as StyleId, ST.style_code as StyleCode ... ..."; using (SqlConnection db = new SqlConnection(InfobaseConString)) { var a = db.Query<(int StyleId, decimal StyleCode)>(query, commandTimeout: 90).ToList(); return a; } } 

But this function returns me only 56 lines using (0,0), Item1=0, Item2=0 . What am I missing?

+7
c # tuples dapper
source share
1 answer

Honestly, it just doesn't support the way tuples work. Derper deserializer maps column values ​​to constructor parameters or properties / fields by name in an object type. ( Source , if you can understand the generated IL).

ValueTuples, on the other hand, still only has property names matching the elements in the tuple ( Item1 , Item2 , etc.), but uses the / ide compiler magic to make them accessible by other names. Thus, StyleId or StyleCode will not be valid property names, they are just aliases for Item1 and Item2 respectively.

You will either have to wait for the command to add explicit ValueTuples support or use the expected property names in your request.

 var query = $@ " SELECT ST.style_id as Item1, ST.style_code as Item2 ... ..."; 
+8
source share

All Articles