asp.net - How do I configure Entity Framework to allow database-generate uuid for PostgreSQL (npgsql)? -
i'm updating our dotnet core project use postgresql on backend instead of microsoft sql server , hit situation 2 tables use guid data type.
error
unhandled exception: system.reflection.targetinvocationexception: exception has been thrown target of invocation. ---> system.invalidoperationexception: property commentid on type database-generated uuid, requires postgresql uuid-ossp extension. add .haspostgresextension("uuid-ossp") context's onmodelcreating.
after little googling realized have enable uuid extension (not sure if can automated somehow) , generated uuid in pgadmin successfully.
create extension "uuid-ossp"; select uuid_generate_v4();
unfortunately dotnet project still complaining same error tho. see in error says add .haspostgresextension("uuid-ossp") onmodelcreating , i've tried in several spots can't seem figure out should added.
as per shay's instruction - after updating latest version of npgsql, uuid extension error gone. here's snippet of onmodelcreating looks others trying out:
protected override void onmodelcreating(modelbuilder builder) { base.onmodelcreating(builder); builder.haspostgresextension("uuid-ossp"); }