Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ public static class SqlServerHierarchyIdDbContextOptionsBuilderExtensions
/// </summary>
/// <param name="optionsBuilder">The builder being used to configure SQL Server.</param>
/// <returns>The options builder so that further configuration can be chained.</returns>
public static SqlServerDbContextOptionsBuilder UseHierarchyId(
this SqlServerDbContextOptionsBuilder optionsBuilder)
public static T UseHierarchyId<T>(
this T optionsBuilder)
where T : SqlEngineDbContextOptionsBuilderBase<T>
{
var coreOptionsBuilder = ((IRelationalDbContextOptionsBuilderInfrastructure)optionsBuilder).OptionsBuilder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal;
/// </summary>
public class SqlServerHierarchyIdCodeGeneratorPlugin : ProviderCodeGeneratorPlugin
{
private static readonly MethodInfo UseHierarchyIdMethodInfo
= typeof(SqlServerHierarchyIdDbContextOptionsBuilderExtensions)
.GetRuntimeMethods()
.First(m => m.Name == nameof(SqlServerHierarchyIdDbContextOptionsBuilderExtensions.UseHierarchyId)
&& m.GetParameters() is [{ ParameterType: var parameterType }]
&& parameterType.TryGetElementType(typeof(SqlEngineDbContextOptionsBuilderBase<>)) is not null);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public override MethodCallCodeFragment GenerateProviderOptions()
=> new(
typeof(SqlServerHierarchyIdDbContextOptionsBuilderExtensions).GetRuntimeMethod(
nameof(SqlServerHierarchyIdDbContextOptionsBuilderExtensions.UseHierarchyId),
[typeof(SqlServerDbContextOptionsBuilder)])!);
=> new(UseHierarchyIdMethodInfo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ public static class SqlServerNetTopologySuiteDbContextOptionsBuilderExtensions
/// </summary>
/// <param name="optionsBuilder">The build being used to configure SQL Server.</param>
/// <returns>The options builder so that further configuration can be chained.</returns>
public static SqlServerDbContextOptionsBuilder UseNetTopologySuite(
this SqlServerDbContextOptionsBuilder optionsBuilder)
public static T UseNetTopologySuite<T>(
this T optionsBuilder)
where T : SqlEngineDbContextOptionsBuilderBase<T>
{
var coreOptionsBuilder = ((IRelationalDbContextOptionsBuilderInfrastructure)optionsBuilder).OptionsBuilder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal;
public class SqlServerNetTopologySuiteCodeGeneratorPlugin : ProviderCodeGeneratorPlugin
{
private static readonly MethodInfo UseNetTopologySuiteMethodInfo
= typeof(SqlServerNetTopologySuiteDbContextOptionsBuilderExtensions).GetRuntimeMethod(
nameof(SqlServerNetTopologySuiteDbContextOptionsBuilderExtensions.UseNetTopologySuite),
[typeof(SqlServerDbContextOptionsBuilder)])!;
= typeof(SqlServerNetTopologySuiteDbContextOptionsBuilderExtensions)
.GetRuntimeMethods()
.First(m => m.Name == nameof(SqlServerNetTopologySuiteDbContextOptionsBuilderExtensions.UseNetTopologySuite)
&& m.GetParameters() is [{ ParameterType: var parameterType }]
&& parameterType.TryGetElementType(typeof(SqlEngineDbContextOptionsBuilderBase<>)) is not null);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal;

namespace Microsoft.EntityFrameworkCore.Infrastructure;

/// <summary>
Expand All @@ -13,8 +11,7 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure;
/// <see cref="O:SqlServerDbContextOptionsExtensions.UseAzureSql" />
/// and it is not designed to be directly constructed in your application code.
/// </remarks>
public class AzureSqlDbContextOptionsBuilder
: RelationalDbContextOptionsBuilder<AzureSqlDbContextOptionsBuilder, SqlServerOptionsExtension>
public class AzureSqlDbContextOptionsBuilder : SqlEngineDbContextOptionsBuilderBase<AzureSqlDbContextOptionsBuilder>
{
/// <summary>
/// Initializes a new instance of the <see cref="AzureSqlDbContextOptionsBuilder" /> class.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal;

namespace Microsoft.EntityFrameworkCore.Infrastructure;

/// <summary>
Expand All @@ -13,8 +11,7 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure;
/// <see cref="O:SqlServerDbContextOptionsExtensions.UseAzureSynapse" />
/// and it is not designed to be directly constructed in your application code.
/// </remarks>
public class AzureSynapseDbContextOptionsBuilder
: RelationalDbContextOptionsBuilder<AzureSynapseDbContextOptionsBuilder, SqlServerOptionsExtension>
public class AzureSynapseDbContextOptionsBuilder : SqlEngineDbContextOptionsBuilderBase<AzureSynapseDbContextOptionsBuilder>
{
/// <summary>
/// Initializes a new instance of the <see cref="AzureSynapseDbContextOptionsBuilder" /> class.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal;

namespace Microsoft.EntityFrameworkCore.Infrastructure;

/// <summary>
Expand All @@ -13,8 +11,7 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure;
/// <see cref="O:SqlServerDbContextOptionsExtensions.ConfigureSqlEngine" />
/// and it is not designed to be directly constructed in your application code.
/// </remarks>
public class SqlEngineDbContextOptionsBuilder
: RelationalDbContextOptionsBuilder<SqlEngineDbContextOptionsBuilder, SqlServerOptionsExtension>
public class SqlEngineDbContextOptionsBuilder : SqlEngineDbContextOptionsBuilderBase<SqlEngineDbContextOptionsBuilder>
{
/// <summary>
/// Initializes a new instance of the <see cref="SqlServerDbContextOptionsBuilder" /> class.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal;

namespace Microsoft.EntityFrameworkCore.Infrastructure;

/// <summary>
/// Base class for SQL Server, Azure SQL, Azure Synapse, etc. specific builders.
/// </summary>
public abstract class SqlEngineDbContextOptionsBuilderBase<TSelf>(DbContextOptionsBuilder optionsBuilder)
: RelationalDbContextOptionsBuilder<TSelf, SqlServerOptionsExtension>(optionsBuilder)
where TSelf : SqlEngineDbContextOptionsBuilderBase<TSelf>
{
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal;

namespace Microsoft.EntityFrameworkCore.Infrastructure;

/// <summary>
Expand All @@ -13,8 +11,7 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure;
/// <see cref="O:SqlServerDbContextOptionsExtensions.UseSqlServer" />
/// and it is not designed to be directly constructed in your application code.
/// </remarks>
public class SqlServerDbContextOptionsBuilder
: RelationalDbContextOptionsBuilder<SqlServerDbContextOptionsBuilder, SqlServerOptionsExtension>
public class SqlServerDbContextOptionsBuilder : SqlEngineDbContextOptionsBuilderBase<SqlServerDbContextOptionsBuilder>
{
/// <summary>
/// Initializes a new instance of the <see cref="SqlServerDbContextOptionsBuilder" /> class.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ReSharper disable InconsistentNaming
namespace Microsoft.EntityFrameworkCore;

public class AzureSqlDbContextOptionsExtensionsTest
{
[ConditionalFact]
public void Can_call_UseNetTopologySuite_with_UseAzureSql()
{
// This test just makes sure we can call/compile UseNetTopologySuite with UseAzureSql.
var optionsBuilder = new DbContextOptionsBuilder();
optionsBuilder.UseAzureSql("Database=Crunchie", b => b.UseNetTopologySuite());
}
}
Loading