@@ -247,9 +247,7 @@ public static bool CanSetValueGenerationStrategy(
247247 /// <param name="schema">The schema in which to create the extension.</param>
248248 /// <param name="name">The name of the extension to create.</param>
249249 /// <param name="version">The version of the extension.</param>
250- /// <returns>
251- /// The updated <see cref="ModelBuilder"/>.
252- /// </returns>
250+ /// <returns>The same builder instance so that multiple calls can be chained.</returns>
253251 /// <remarks>
254252 /// See: https://www.postgresql.org/docs/current/external-extensions.html
255253 /// </remarks>
@@ -274,9 +272,7 @@ public static ModelBuilder HasPostgresExtension(
274272 /// </summary>
275273 /// <param name="modelBuilder">The model builder in which to define the extension.</param>
276274 /// <param name="name">The name of the extension to create.</param>
277- /// <returns>
278- /// The updated <see cref="ModelBuilder"/>.
279- /// </returns>
275+ /// <returns>The same builder instance so that multiple calls can be chained.</returns>
280276 /// <remarks>
281277 /// See: https://www.postgresql.org/docs/current/external-extensions.html
282278 /// </remarks>
@@ -286,6 +282,78 @@ public static ModelBuilder HasPostgresExtension(
286282 string name )
287283 => modelBuilder . HasPostgresExtension ( null , name ) ;
288284
285+ /// <summary>
286+ /// Registers a PostgreSQL extension in the model.
287+ /// </summary>
288+ /// <param name="modelBuilder">The model builder in which to define the extension.</param>
289+ /// <param name="schema">The schema in which to create the extension.</param>
290+ /// <param name="name">The name of the extension to create.</param>
291+ /// <param name="version">The version of the extension.</param>
292+ /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
293+ /// <returns>The same builder instance so that multiple calls can be chained.</returns>
294+ /// <remarks>
295+ /// See: https://www.postgresql.org/docs/current/external-extensions.html
296+ /// </remarks>
297+ /// <exception cref="ArgumentNullException"><paramref name="modelBuilder"/></exception>
298+ public static IConventionModelBuilder ? HasPostgresExtension (
299+ this IConventionModelBuilder modelBuilder ,
300+ string ? schema ,
301+ string name ,
302+ string ? version = null ,
303+ bool fromDataAnnotation = false )
304+ {
305+ if ( modelBuilder . CanSetPostgresExtension ( schema , name , version , fromDataAnnotation ) )
306+ {
307+ modelBuilder . Metadata . GetOrAddPostgresExtension ( schema , name , version ) ;
308+ return modelBuilder ;
309+ }
310+
311+ return null ;
312+ }
313+
314+ /// <summary>
315+ /// Registers a PostgreSQL extension in the model.
316+ /// </summary>
317+ /// <param name="modelBuilder">The model builder in which to define the extension.</param>
318+ /// <param name="name">The name of the extension to create.</param>
319+ /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
320+ /// <returns>The same builder instance so that multiple calls can be chained.</returns>
321+ /// <remarks>
322+ /// See: https://www.postgresql.org/docs/current/external-extensions.html
323+ /// </remarks>
324+ /// <exception cref="ArgumentNullException"><paramref name="modelBuilder"/></exception>
325+ public static IConventionModelBuilder ? HasPostgresExtension (
326+ this IConventionModelBuilder modelBuilder ,
327+ string name ,
328+ bool fromDataAnnotation = false )
329+ => modelBuilder . HasPostgresExtension ( schema : null , name , version : null , fromDataAnnotation ) ;
330+
331+ /// <summary>
332+ /// Returns a value indicating whether the given PostgreSQL extension can be registered in the model.
333+ /// </summary>
334+ /// <remarks>
335+ /// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see>, and
336+ /// <see href="https://aka.ms/efcore-docs-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
337+ /// for more information and examples.
338+ /// </remarks>
339+ /// <param name="modelBuilder">The model builder.</param>
340+ /// <param name="schema">The schema in which to create the extension.</param>
341+ /// <param name="name">The name of the extension to create.</param>
342+ /// <param name="version">The version of the extension.</param>
343+ /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
344+ /// <returns><see langword="true" /> if the given value can be set as the default increment for SQL Server IDENTITY.</returns>
345+ public static bool CanSetPostgresExtension (
346+ this IConventionModelBuilder modelBuilder ,
347+ string ? schema ,
348+ string name ,
349+ string ? version = null ,
350+ bool fromDataAnnotation = false )
351+ {
352+ var annotationName = PostgresExtension . BuildAnnotationName ( schema , name ) ;
353+
354+ return modelBuilder . CanSetAnnotation ( annotationName , $ "{ schema } ,{ name } ,{ version } ", fromDataAnnotation ) ;
355+ }
356+
289357 #endregion
290358
291359 #region Enums
0 commit comments