-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNpgsqlComplexIndexDbContextOptionsExtensions.cs
More file actions
32 lines (29 loc) · 1.26 KB
/
Copy pathNpgsqlComplexIndexDbContextOptionsExtensions.cs
File metadata and controls
32 lines (29 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.Extensions.DependencyInjection;
namespace EFCore.ComplexIndexes.PostgreSQL;
/// <summary>
/// Runtime wiring for expression indexes on PostgreSQL.
/// </summary>
public static class NpgsqlComplexIndexDbContextOptionsExtensions
{
extension(DbContextOptionsBuilder optionsBuilder)
{
/// <summary>
/// Replaces the migrations SQL generator with one that can render expression indexes
/// defined via <c>HasExpressionIndex</c>. Call this after <c>UseNpgsql(...)</c>:
/// <code>options.UseNpgsql(connectionString).UseNpgsqlComplexIndexes();</code>
/// </summary>
public DbContextOptionsBuilder UseNpgsqlComplexIndexes()
=> optionsBuilder.ReplaceService<IMigrationsSqlGenerator, NpgsqlComplexIndexSqlGenerator>();
}
extension(IServiceCollection services)
{
/// <summary>
/// Registers the migrations SQL generator required for expression indexes
/// when using a custom internal service provider.
/// </summary>
public IServiceCollection AddNpgsqlComplexIndexes()
=> services.AddScoped<IMigrationsSqlGenerator, NpgsqlComplexIndexSqlGenerator>();
}
}