0

In an ASP.NET Core 5 MVC application, I have this call:

var result = ctx.ExecQuery<(string Item1)>("select '' as Item1");

This throws 5 compile-time errors starting at

Invalid expression term 'string'

The following works:

var result = ctx.ExecQuery<(string Item1, bool _)>("select '' as Item1");

How to create a ValueTuple containing a single member so that using bool _ can avoided?

Andrus
  • 26,339
  • 60
  • 204
  • 378
  • `ExecQuery` throws `type string does not have a default constructor`. Is it reasonable to modify `ExecQuery` to support value types ? – Andrus Jan 17 '21 at 08:17
  • 2
    isn't the whole _point_ of a tuple is to pack _multiple_ items? – Franz Gleichmann Jan 17 '21 at 08:21
  • 1
    In case in question, point of tuple is to create class with `one` item. ExecQuery creates class and assigns values to its properties. There is `ValueTuple` class which has one item and can used to fix the issue . Do you think that `ValueTuple` is pointless C# defect ? – Andrus Jan 17 '21 at 08:44
  • 1
    https://github.com/dotnet/csharplang/issues/1595 – 41686d6564 stands w. Palestine Jan 17 '21 at 08:57
  • Does this answer your question? [C# 7:How can I deconstruct an object into a single value using a tuple?](https://stackoverflow.com/questions/44975958/c-sharp-7how-can-i-deconstruct-an-object-into-a-single-value-using-a-tuple) – GSerg Jan 17 '21 at 08:58
  • If you don't need it to be named, then maybe you can use `.ExecQuery>`? – 41686d6564 stands w. Palestine Jan 17 '21 at 09:01
  • @FranzGleichmann https://stackoverflow.com/questions/44975958/c-sharp-7how-can-i-deconstruct-an-object-into-a-single-value-using-a-tuple#comment104179944_44989440 – GSerg Jan 17 '21 at 09:29

0 Answers0