-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Closed
Description
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
- https://stackoverflow.com/questions/8270205/how-do-i-perform-an-insert-and-return-inserted-identity-with-dapper
- https://stackoverflow.com/questions/50650985/dapper-for-net-core-insert-into-a-table-and-return-id-of-inserted-row/50651620
- https://dapper-tutorial.net/knowledge-base/37453324/the-importance-of--select-cast-scope-identity---as-int---in-dapperorm
Metadata
Metadata
Assignees
Labels
No labels