No mapping exists from object type System.RuntimeType to a known managed provider native type

entity-framework

Question

I have a stored procedure with the signature

PROCEDURE [dbo].[spValidateID]
    @ScanCode       VARCHAR(50),
    @Name           VARCHAR(50) = NULL OUTPUT,
    @ScanTime       DATETIME = NULL OUTPUT,
    @ValidationCode INT = 0 OUTPUT

This is supposed to return a validationCode and also populate the name and scanTime variables. I need to give it scanCode value while calling.

in my C# code I am doing like this.

using (var context = new DBEntities())
{
    var pScanCode = new SqlParameter("ScanCode", scanCode);
    var opName = new SqlParameter("Name", name);
    var opScanTime = new SqlParameter("ScanTime", scanTime);
    var opValidationCode = new SqlParameter("ValidationCode", validationCode);

    var test = context.ExecuteStoreQuery<int>("spValidateID @ScanCode, @Name, @ScanTime, @ValidationCode", pScanCode, opName, opScanTime, opValidationCode);
}

but while running this I m getting error No mapping exists from object type System.RuntimeType to a known managed provider native type.

any idea??

1
11
10/18/2017 5:43:40 PM

Accepted Answer

You are missing ouput settings for your sqlparameters and @. Your code should look something like this:

SqlParameter pScanCode = new SqlParameter("@ScanCode", ScanCode);
SqlParameter opName = new SqlParameter("@Name", name);
opName.Direction = System.Data.ParameterDirection.Output;   //Important!
SqlParameter opScanTime = new SqlParameter("@ScanTime", scanTime);
opScanTime.Direction = System.Data.ParameterDirection.Output;   //Important!
SqlParameter opValidationCode = new SqlParameter("@ValidationCode ", validationCode);
opValidationCode.Direction = System.Data.ParameterDirection.Output;   //Important!
5
10/18/2017 5:56:02 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow