Skip to content

IDENTITY retrieval error: No mapping exists from DbType UInt32 to a known SqlDbType. #1490

@a3nick

Description

@a3nick

Trying to retrieve the inserted identity value on a SqlServer table a receive the following error:

System.ArgumentException
No mapping exists from DbType UInt32 to a known SqlDbType.

this happens using both async or non-async methods and with these solutions

// USING SCOPE_IDENTITY()
var id = await Connection.QuerySingleAsync<int>(@"
    INSERT INTO SOME_TABLE(VAL) VALUES (@VAL); 
    SELECT SCOPE_IDENTITY()"
    , new { VAL });

// USING SCOPE_IDENTITY() WITH CAST
var id = await Connection.QuerySingleAsync<int>(@"
    INSERT INTO SOME_TABLE(VAL) VALUES (@VAL); 
    SELECT CAST(SCOPE_IDENTITY() as int)"
    , new { VAL });

// USING OUTPUT CLAUSE
var id = await Connection.QuerySingleAsync<int>(
    @"INSERT INTO SOME_TABLE(VAL) 
    OUTPUT inserted.Id 
    VALUES (@VAL)"
    , new { VAL });

tried also with QueryAsync<int> and QueryAsync (dynamic result excpected) with the same result

WEB REFS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions