Skip to content

Commit

Permalink
Remove UseSqlServer overloads that take SqlConnectionStringBuilder
Browse files Browse the repository at this point in the history
This reverts commit cf72e2e.

Part of #15642
  • Loading branch information
bricelam committed Jun 25, 2019
1 parent 01c26cc commit 511d365
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Data.Common;
using JetBrains.Annotations;
using Microsoft.Data.SqlClient; // Note: Hard reference to SqlClient here.
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal;
Expand Down Expand Up @@ -89,56 +88,6 @@ public static DbContextOptionsBuilder<TContext> UseSqlServer<TContext>(
=> (DbContextOptionsBuilder<TContext>)UseSqlServer(
(DbContextOptionsBuilder)optionsBuilder, connectionString, sqlServerOptionsAction);

/// <summary>
/// Configures the context to connect to a Microsoft SQL Server database.
/// </summary>
/// <typeparam name="TContext"> The type of context to be configured. </typeparam>
/// <param name="optionsBuilder"> The builder being used to configure the context. </param>
/// <param name="connectionStringBuilderAction">
/// An action to configure the database connection string by using
/// <see cref="SqlConnectionStringBuilder" />.
/// </param>
/// <param name="sqlServerOptionsAction">An optional action to allow additional SQL Server specific configuration.</param>
/// <returns> The options builder so that further configuration can be chained. </returns>
public static DbContextOptionsBuilder<TContext> UseSqlServer<TContext>(
[NotNull] this DbContextOptionsBuilder<TContext> optionsBuilder,
[NotNull] Action<SqlConnectionStringBuilder> connectionStringBuilderAction,
[CanBeNull] Action<SqlServerDbContextOptionsBuilder> sqlServerOptionsAction = null)
where TContext : DbContext
=> (DbContextOptionsBuilder<TContext>)UseSqlServer(
(DbContextOptionsBuilder)optionsBuilder, connectionStringBuilderAction, sqlServerOptionsAction);

/// <summary>
/// Configures the context to connect to a Microsoft SQL Server database.
/// </summary>
/// <param name="optionsBuilder"> The builder being used to configure the context. </param>
/// <param name="connectionStringBuilderAction">
/// An action to configure the database connection string by using
/// <see cref="SqlConnectionStringBuilder" />.
/// </param>
/// <param name="sqlServerOptionsAction">An optional action to allow additional SQL Server specific configuration.</param>
/// <returns> The options builder so that further configuration can be chained. </returns>
public static DbContextOptionsBuilder UseSqlServer(
[NotNull] this DbContextOptionsBuilder optionsBuilder,
[NotNull] Action<SqlConnectionStringBuilder> connectionStringBuilderAction,
[CanBeNull] Action<SqlServerDbContextOptionsBuilder> sqlServerOptionsAction = null)
{
Check.NotNull(connectionStringBuilderAction, nameof(connectionStringBuilderAction));

var connectionStringBuilder = new SqlConnectionStringBuilder
{
ConnectRetryCount = 0
};
if (optionsBuilder.Options.ContextType != typeof(DbContext))
{
connectionStringBuilder.InitialCatalog = optionsBuilder.Options.ContextType.Name;
}

connectionStringBuilderAction(connectionStringBuilder);

return UseSqlServer(optionsBuilder, connectionStringBuilder.ConnectionString, sqlServerOptionsAction);
}

// Note: Decision made to use DbConnection not SqlConnection: Issue #772
/// <summary>
/// Configures the context to connect to a Microsoft SQL Server database.
Expand Down
1 change: 0 additions & 1 deletion test/EFCore.Design.Tests/TestUtilities/BuildSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class BuildSource
BuildReference.ByName("System.Collections"),
BuildReference.ByName("System.ComponentModel.Annotations"),
BuildReference.ByName("System.Data.Common"),
BuildReference.ByName("Microsoft.Data.SqlClient"),
BuildReference.ByName("System.Linq.Expressions"),
BuildReference.ByName("System.Runtime"),
BuildReference.ByName("System.Runtime.Extensions"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,5 @@ public void Can_add_extension_with_legacy_paging()
Assert.True(extension.RowNumberPaging.HasValue);
Assert.True(extension.RowNumberPaging.Value);
}

[ConditionalFact]
public void Can_add_extension_with_connection_stringbuilder_action_generic()
{
var optionsBuilder = new DbContextOptionsBuilder<SampleDbContext>();
optionsBuilder.UseSqlServer(csb => { csb.DataSource = "Kilimanjaro"; });

var extension = optionsBuilder.Options.Extensions.OfType<SqlServerOptionsExtension>().Single();
Assert.Equal("Data Source=Kilimanjaro;Initial Catalog=SampleDbContext;ConnectRetryCount=0", extension.ConnectionString);
Assert.Null(extension.Connection);
}

[ConditionalFact]
public void Can_add_extension_with_connection_stringbuilder_action()
{
var optionsBuilder = new DbContextOptionsBuilder();
optionsBuilder.UseSqlServer(csb => { csb.DataSource = "Kilimanjaro"; });

var extension = optionsBuilder.Options.Extensions.OfType<SqlServerOptionsExtension>().Single();
Assert.Equal("Data Source=Kilimanjaro;ConnectRetryCount=0", extension.ConnectionString);
Assert.Null(extension.Connection);
}

private class SampleDbContext : DbContext
{
}
}
}

0 comments on commit 511d365

Please sign in to comment.