Skip to content

Specified cast is not valid when using QueryAsync #346

Closed

Description

@pranavmehta

I have a stored procedure that selects a single big int - something like: select 10 as 'Id'.

I have the following code which works perfectly fine:

long Id = Conn.Query<long>("GetId", new { foo = bar }, commandType: CommandType.StoredProcedure).First();

However, I am unable to get it to work with QueryAsync. It always fails with "The specified cast is not valid" exception. What is the correct way to use the Async version of above code?

Note: I am able get QueryAsync to work when using complex types, but fails for simple types like in above example

Activity

  1. tms commented on Sep 29, 2015

    @tms
    Contributor

    Hmm, @mgravell, is this just a case of needing to add the ChangeType fallback to where the async results are read? I assume the DB is actually returning something that isn't directly a long in this case, like the situations that required the change in the synchronous code before.

  2. NickCraver commented on Oct 10, 2015

    @NickCraver
    Member

    @tms yep pretty close - I was making sure this wasn't already solved somewhere but it has been - in PR #338. I'll merge it in shortly.

  3. added a commit that references this issue on Oct 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions