0

I'm struggling w/some Dapper code. I have a singular, all encompassing list that I'm using in a couple different calls (handled by my stored procedure). This works well in most cases, but I'm running into issues where list items known to have a value are returning NULL to the list. I am reusing this list throughout.. maybe that's an issue?

This has happened to me in three different scenarios in this project, so I'm confident there's something I'm missing.

I wish I could share more, but the code is privileged. Here's the sp call. Now picture a list which is 50 items wide, but depending up on the parameter, only certain fields are returned from by the stored procedure. Again, I would expect varying numbers of fields to be NULL, but I am also certain that fields I expect are being returned NULL, why I do receive others. For what its worth, NULLs may appear to my list at any position (first, middle, last item).

public List<buildrec> RecBuilder(string recType)
{
    using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(cnstr("myDB")))
    {
        var Params = new DynamicParameters();
        Params.Add("rtype", recType);                
        return connection.Query<buildCMEDI>("mySP" , new { RTYPE = recType}, commandTimeout: 180).ToList();                
    }
}

Ex. I pass the parameter of redtruck, all stored information on red trucks is returned

Towing_capacity, Engine_size, make, model, Number_doors, convertible (in this example, I'd expect to have values for all but convertible.

If I passed bluecar, I'd expect to have values for all, but Towing_capacity and any convertibles.

continuing the example I receive no information for bluecar : convertible, though I am certain there is data.

I've check numerous times, spelling, sp calls, etc. If I call the SP from SSMS, works as intended. when reviewing the raw list results in VS, I see the intended data. However, all is returned to my list variables a NULL.

I tried to be thorough, please share any thoughts.. I'm stumped.

3
  • 1
    What I see here is that you are creating DynamicParameters, but don't use them. Instead you use new { RTYPE = recType}. Depending on what we can't see, parameter names mayu or may not be case-sensitive. So the parameter should be @rtype or @RTYPE? Can't guess. Also can't judge if they are mapping issues in buildCMEDI type or not. Commented Jul 21, 2024 at 18:01
  • 2
    You need to pass your params to the dapper query: return connection.Query<buildCMEDI>("mySP" , Params, commandTimeout: 180, commandType: CommandType.StoredProcedure).ToList(); . I have also explicitly mentioned the commandType to be of Stored Procedure. Also change: Params.Add("@rtype", recType); Commented Jul 21, 2024 at 20:08
  • Thank you both.. I thought certain all was named properly.. I overlooked an AS in my SP column naming. Thanks again, I believe this is resolved. Commented Jul 22, 2024 at 15:23

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.