Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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??

like image 666
Gautam Avatar asked Jul 17 '12 13:07

Gautam


1 Answers

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!
like image 182
Gregor Primar Avatar answered Sep 28 '22 03:09

Gregor Primar