Skip to content

Commit 09971b3

Browse files
Added the 'AzureSqlDbContextOptionsBuilderExtensions' extension class to support Azure SQL Db's.
1 parent 44bdc59 commit 09971b3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Microsoft.EntityFrameworkCore.Infrastructure;
2+
using Microsoft.EntityFrameworkCore.SqlServer.Infrastructure;
3+
using Microsoft.Extensions.DependencyInjection;
4+
5+
namespace Microsoft.EntityFrameworkCore;
6+
7+
public static class AzureSqlDbContextOptionsBuilderExtensions
8+
{
9+
public static AzureSqlDbContextOptionsBuilder UseNodaTime(
10+
this AzureSqlDbContextOptionsBuilder azureBuilder)
11+
{
12+
// Access the underlying OptionsBuilder
13+
var coreOptionsBuilder = ((IRelationalDbContextOptionsBuilderInfrastructure)azureBuilder).OptionsBuilder;
14+
15+
// Look for the NodaTime extension or create a new instance if not found
16+
var extension = coreOptionsBuilder.Options.FindExtension<NodaTimeOptionsExtension>()
17+
?? new NodaTimeOptionsExtension();
18+
19+
// Add or update the extension in the options
20+
((IDbContextOptionsBuilderInfrastructure)coreOptionsBuilder).AddOrUpdateExtension(extension);
21+
22+
return azureBuilder;
23+
}
24+
}

0 commit comments

Comments
 (0)