Skip to content

Null Reference Exception during INSERT/SELECT #383

@jchannon

Description

@jchannon

I have a SQL statement that runs fine with ngpsql v2.2.0 and dapper 1.36 which looks like so

INSERT INTO MyTable (Name,Msg) Values(@Name, @Msg); 
SELECT MAX(Id) FROM MyTable

I am using it like so:

connection.Query<int>(sql,
                     new {
                       item.Name,
                       item.Msg
                     }).First();

However when it runs with ngpsql v3.0.3 or ngpsql v3.1.0-alpha3 I get a NullReferenceException

Exception(Type:NullReferenceException):Object reference not set to an instance of an object
  at Dapper.SqlMapper+<QueryImpl>d__11`1[System.Int32].MoveNext () [0x00000] in <filename unknown>:0
  at System.Collections.Generic.List`1[System.Int32].AddEnumerable (IEnumerable`1 enumerable) [0x00000] in <filename unknown>:0
  at System.Collections.Generic.List`1[System.Int32]..ctor (IEnumerable`1 collection) [0x00000] in <filename unknown>:0
  at System.Linq.Enumerable.ToList[Int32] (IEnumerable`1 source) [0x00000] in <filename unknown>:0
  at Dapper.SqlMapper.Query[Int32] (IDbConnection cnn, System.String sql, System.Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) [0x00000] in <filename unknown>:0

Any ideas?

I've also logged it with ngpsql as I'm unsure where the issue is: npgsql/npgsql#857

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