Description
We have a scenario where there is an entity with a UUID field which acts as the primary key:
[Primary]
[Map("some_pk_field")]
public Guid SomePkField { get; set; }
We then have the field on the db side setup as a UUID with auto generation via default with not null:
some_pk_field uuid not null default gen_random_uuid()
When we try to insert into it we always get an empty guid as the PK, this is assumed to be due to Guid
in C# being a value type so cannot be null, so its never triggering the default DB backed UUID generation.
Given this assumption we decided to make the Guid field nullable (Guid?
) however when we try to insert with a null Guid
RepoDb tells us that we need to provide an entry to the pk field.
We have also run the script to verify PKs for tables and this returns:
some_pk_field ,true,false,false,uuid // The 2nd field being true for it being primary key
Expected Behaviour
I expected that if a Guid
was provided as the PK and it was an empty guid, it would use the DB default to create the PK and it would be returned by the Insert
method. However if there is some legitimate reason why someone may need to insert an empty guid in which case the above expected behaviour could not be true, then a nullable guid with a null value should provoke the same behaviour.
This is based off a conversation had in gitter around the subject where @mikependon requested these issues be raised here
Library Version:
Example: RepoDb v1.12.8 and RepoDb.Postgres v1.1.4