Dapper icon indicating copy to clipboard operation
Dapper copied to clipboard

Empty result set creates SelectListItem Item with NULL parameters?

Open baileybarberscargill opened this issue 2 years ago • 3 comments

When calling a stored procedure, using QueryAsync, and the result returns no results, it still creates a SelectListItem with 1 item as an item with "NULL" in the value & text.

baileybarberscargill avatar Nov 06 '23 16:11 baileybarberscargill

can you clarify "returns no results"? perhaps a concrete example - does the stored proc not do a select? and is this QueryAsync() or QueryAsync<T>() for some T ?

SelectListItem isn't a Dapper concept, so I'd also need more context to understand what you're doing here

mgravell avatar Nov 06 '23 16:11 mgravell

Apologies, for clarification:

The query returns 0 rows, as it's result (this is expected). We are selecting and Id and Name. We are only using QueryAsync, with the function return type being an IEnumerable<SelectListItem>

baileybarberscargill avatar Nov 06 '23 16:11 baileybarberscargill

We are only using QueryAsync, with the function return type being an IEnumerable<SelectListItem>

so... you're using QueryAsync<SelectListItem>(...) ? I'm not just being pedantic - I need to be very precise here: the details matter

I do not believe there is any scenario in which a query returning zero rows, when used in this way, will result in a non-zero number of rows. Can we try to boil this down to a runnable, repeatable example - so that we can investigate? What exactly are you seeing? for example, imagine your code looks like:

var data = await conn.Query<SelectListItem>(sql, args);

What happens if we do:

var count = data.Count();
Debug.WriteLine(count); // or Console.WriteLine, etc

What number do you see there? Is it 1? or 0? And are you absolutely positively 100% sure that your query didn't return a row? Can we check that?

mgravell avatar Nov 06 '23 17:11 mgravell