Postgres ormlite id not returning

I am getting the following generated sql when trying to insert into postgres which is throwing an error about the duplicated returning syntax. tried versions 5.8 and 5.8.1

Db.Insert(tblPoco, selectIdentity: true);

produces

INSERT INTO "tablename" (..fields...) VALUES (..values...) RETURNING "id" RETURNING "id"

Please post a Minimal Reproducible Example I can run locally to repro the issue please.

This will pretty much show it, just needs a postgrse db

public class Test
    {
        [Fact]
        public void Test1()
        {
            var dbFactory = new OrmLiteConnectionFactory(Config.PostgreSqlConfig.ConnectionString, new PostgreSqlDialectProvider());
                
            using var db = dbFactory.OpenDbConnection();
            
            db.DropAndCreateTable<TblDto>();

            using (var capture = new CaptureSqlFilter())
            {
                db.Insert(new TblDto(), selectIdentity: true);
                Console.WriteLine(capture.SqlCommandHistory.FirstOrDefault());
            }
            
            var id = db.Insert(new TblDto(), selectIdentity: true);
        }
        
        public class TblDto : IHasId<int>
        {
            [AutoId]
            public int Id { get; }
        }
    }

[AutoId] is for Guids, use [AutoIncrement] for auto incrementing integer primary keys

FYI it’s easier to log the SQL with:

OrmLiteUtils.PrintSql();

Can later disable SQL logging with:

OrmLiteUtils.UnPrintSql();

This just uses the BeforeExecFilter behind the scenes.

doh! that was it … attribute blindness!

Thanks for the PrintSql tip :+1:

1 Like