I'm getting a NullReferenceException when I execute this code:
var insertTransaction = @"INSERT INTO [192.168.1.55].databaseName.dbo.tableName
(Date, Desc)
VALUES(GETDATE(),
@Description)
SELECT Scope_identity()";
var result = _sqlMapper.Query<int>(insertTransaction,
new
{
Description = "some description"
});
where _sqlMapper is an instance of Dapper.SqlMapper
If I remove SELECT Scope_identity()
I don't get the exception.
The exception stack trace says the exception is thrown here:
at Dapper.SqlMapper.d__11`1.MoveNext() in d:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1583
- Why does
SELECT Scope_identity()
create a null object and how can I fix it? - Why does the stack trace display a file path which does not exist on my local machine?
UPDATE: Dapper version = 1.40.0.0, Runtime Version = v4.0.30319 DLL = C:\src\packages\Dapper.1.40\lib\net45\Dapper.dll
UPDATE: If I execute the query in Management Studio, the row gets inserted however the scope_identity returned is null.