QueryAsync<T> Returns empty object of T/

I am running the latest stable .NET SDK 2.7.12. Here is the code snippet:

    public async Task<User> GetByEmailAsync(string email)
        var query = new QueryRequest("select e.* from `elite-app-data` e where e.email=$email")
        .AddNamedParameter("$email", email);

        var result = await _bucket.QueryAsync<User>(query);

        return result.FirstOrDefault();

I am able to add documents, the query does work on the Web Console and if I use a dynamic object I get my data. So what am I missing here?


Does it mean that my post will be withdrawn?

Hi @etoilexxx,

That message just meants that @ingenthr has withdrawn his response.

As for your question, I need a little more information. What do you expect this code to do? What is it actually doing?

Some ideas for you to drill in a little more:

In your result object, what is the value of Success? Is there an exception? I think if you step through this with a debugger, you’re going to get a better idea of what’s going on.

Sorry about that. See below my screenshot of the result:

I expect to see data populated but it’s not when I am using a concrete type.

I am not expert in .NET but check out Wrong for AddNamedParameter with statement contain percent character


.AddNamedParameter(“email”, email)

1 Like

Okay, looks like the query is executing, so that’s good! Now I suspect a mismatch between the results and your C# class property names. Would you post an example of the results of your query (just the first record would be enough) and also your User class?

vsr1, that didn’t help. Besides, the dynamic object works with or without the $.

Matt, it’s the user class, I forgot I had protected setters on my model which QueryAsync can’t get to. Does this mean the compiler spins up a subclass on the fly and use that?



That could be a good approach. I’m not sure, but creating a custom serializer and/or dipping into reflection might also work? But that might be more trouble than it’s worth.

:ok_hand: I am keeping it simple. Thanks guys.

1 Like