I work with 'PostgreSql' in .NET using Entity Framework (POCO approach).
My goal is to create a new record in database generating Id (uuid) on the database side and retrieve generated Id to the server (such scenario works perfectly with SQL Server).
My model looks like:
public class MyClass
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
public string Name { get; set; }
}
In PostgreSql Column 'Id' has default value 'uuid_generate_v4()'
When I try to add a new object to the DB using EF, I Get the following error:
A null store-generated value was returned for a non-nullable member 'Id' of type...
I check SQL queries which EF sends to the PostgreSQL:
INSERT INTO "public"."MyClass"("Name") VALUES ("Test");
SELECT currval(pg_get_serial_sequence('"public"."MyClass"', 'Id')) AS "Id"
First one looks good. If I execute it, the new row is created in DB (with newly generated id) Second one returns NULL and the name of the column is 'Id bigint'. It seems, that this feature works only for numeric ids.
Is it possible to make it work for auto-generated column of 'uuid' type?