Reputation: 9
My model looks like this
public class Model
{
public int ID { get; set; }
public List<AnotherModel> Sample{ get; set; }
}
public class AnotherModel
{
public int RequestID { get; set; }
public int RequestName { get; set; }
}
I'm calling stored procedure and passing this object as follows.
var result = await _Connection.QueryFirstOrDefaultAsync<ResponseModel>($@"EXEC GetRequestData @ID=@ID,@Names= @Sample", new
{
Model.ID,Model.Sample
});
Stored procedure
DECLARE @ID int ,@Names varchar(MAX)
DECLARE @Table TABLE (RequestID int, RequestName int)
INSERT INTO @Request_Table
SELECT RequestID , RequestName FROM OPENJSON(@Names )
WITH (TempDataset nvarchar(max) as json) A
OUTER APPLY OPENJSON(A.TempDataset )
WITH (RequestID int '$.RequestID',
RequestName int '$.RequestName')
...........Query tables along with Table created above
This throws an exception
The member of type ....Models.AnotherModel cannot be used as a parameter value
I'm trying to pass list of values to the procedure. What am i missing here? Any alternate solution will also work if possible.
Tried passing list of object to stored procedure which is failing
Upvotes: 0
Views: 30