2
Vote

ExecuteReturnLastId within postgres

description

Hi,

I used ExecuteReturnLastId as follow sample
var id = dbContext.Insert("app").Column("name", newAppName).ExecuteReturnLastId<Int32>("id");
but the result is null. I tried to debug from the lastest main code and I found that in the
ExecuteQueryHandler.cs I have the follow piece of code
_command.Data.InnerCommand.CommandText = _command.Data.Sql.ToString();
with _command.Data.InnerCommand.CommandText == "select lastval();"
and _command.Data.Sql.ToString() == "insert into app(name) values(:name);"

as result the "select lastval();" not get appended to the sql query after the insert but the insert query simply overwrite the select last sql command text.

Attached a workaround patch, not sure if works in all cases but for me it did the trick.

file attachments

comments

roydux wrote Dec 16, 2015 at 12:37 AM

It's seemd that column id is not primary key,or not be set to auto increment.can you have a check?

wrote Aug 29, 2016 at 7:15 AM