Home > Enterprise >  How do I bind stored procedure single result set with single class object result?
How do I bind stored procedure single result set with single class object result?

Time:10-13

I have a stored procedure which returns following result set:

Id : int
Name : string
Image : string
Address : string

Code:

public class SPResultSet
{
       public int Id { get; set; }
       public string Name { get; set; }
       public string Image { get; set; }
       //other additional properties
} 

var data = ctx.Database
              .SqlQuery<SPResultSet>("[dbo].[GET_Data] params", sqlParameters)
              .FirstOrDefault();

Error :

System.ArgumentException: 'No mapping exists from object type System.Collections.Generic.List`1[[System.Data.SqlClient.SqlParameter, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] to a known managed provider native type.'

How do I bind the stored procedure's single result set with single class object result?

Note: the stored procedure returns only 1 row of data.

CodePudding user response:

You should not pass the parameters as list, you should pass the each parameter to the stored procedure.

Or it could be passed as sqlParameters.ToArray() in your case.

Note: It would be great if you provide the complete code with parameters you are passing and the stored procedure.

  • Related