title: How do I configure Entity Framework to allow database-generate uuid for PostgreSQL (npgsql)?
body: <p>I'm updating our dotnet core project to use PostgreSQL on the backend instead of Microsoft SQL Server and hit a situation with two tables that use a GUID as the data type.  </p>
  
  <p><strong>ERROR</strong></p>
  
  <pre><code>Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---&gt; System.InvalidOperationException: Property CommentID on type is a database-generated uuid, which requires the PostgreSQL uuid-ossp extension. Add .HasPostgresExtension("uuid-ossp") to your context's OnModelCreating.
  </code></pre>
  
  <p>After a little googling I then realized I have to enable the uuid extension (not sure if this can be automated somehow) and then generated a uuid in pgAdmin successfully.  </p>
  
  <pre><code>CREATE EXTENSION "uuid-ossp";
  SELECT uuid_generate_v4();
  </code></pre>
  
  <p>Unfortunately my dotnet project is still complaining with the same error tho.  I see in the error it says to <strong>add .HasPostgresExtension("uuid-ossp") to OnModelCreating</strong> and I've tried in several spots but can't seem to figure out where specifically it should be added.</p>