Guid return on insert

Trying to return a Guid PK upon insert.

I saw this post Getting unique identifier primary key from SQL Server on INSERT

And have dug through the codebase to find the ReturnOnInsertAttribute (which was renamed in this commit: https://github.com/ServiceStack/ServiceStack/commit/b366efdaf9519acb6ffcac9d7b65cbd056b4d6a0), and how it is used in the ModelDefinition and FieldDefinition.cs.

Yet I have neither available (ReturnAttribute or ReturnOnInsertAttribute) in version 5.0.2. Am I missing something?

Out of our 78 Domain models, 70 of them use Guid PK’s, and I would like to refrain from the code in the previous question linked all throughout our codebase.

Thanks!

Nevermind, looking through the commit logs, it looks as though this wasn’t really introduced until after the 5.0.2 release (which is why I don’t see it).

I like where it’s going though! Any timelines for when this is slated for release?

That’s only for sequences, but I’ve just added for Auto populating GUID’s in this commit which will let you specify that you want to auto populate GUID Primary Keys with:

public class Table
{
    [AutoId]
    public Guid Id { get; set; }
}

It uses newid() for SQL Server and uuid_generate_v4() for PostgreSQL which requires installing the extension on the DB it’s used:

CREATE EXTENSION IF NOT EXISTS "uuid-ossp"

Where it will return the value populated by the RDBMS, in all other RDBMS’s OrmLite will populate the Guid on INSERT with Guid.NewGuid(). In all DB’s it will populate the instance with the auto populated GUID, e.g:

var row = new Table { ... };
db.Insert(row);
row.Id //= Auto populated with new Guid

This change is available from v5.0.3 that’s now available on MyGet.

We don’t have set/committed release dates, but hopefully within 2 weeks.

1 Like

You sir are a gentleman and a scholar

1 Like