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

entity-framework

Question

I have the signature in a saved procedure.

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

The name and scanTime variables should also be filled in, and this is expected to produce a validationCode as well. While calling, I must provide a scanCode value.

This is what I'm doing in my C# code.

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);
}

yet I'm receiving an error when doing this. There is no mapping for objects of type System. RuntimeType to a well-known native managed provider type

Any ideas?

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

Accepted Answer

For your sqlparameters and @, output settings are missing. Your code should like the following:

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