Skip to content

Commit

Permalink
Default to (localdb)\MSSQLLocalDB
Browse files Browse the repository at this point in the history
Part of 189
  • Loading branch information
bricelam committed Jun 5, 2019
1 parent fb1e49c commit 3c927b1
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/EntityFramework.SqlServer/SqlProviderServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace System.Data.Entity.SqlServer
/// or through code-based registration in <see cref="DbConfiguration" />.
/// The services resolved are:
/// Requests for <see cref="IDbConnectionFactory" /> are resolved to a Singleton instance of
/// <see cref="System.Data.Entity.Infrastructure.SqlConnectionFactory" /> to create connections to SQL Express by default.
/// <see cref="System.Data.Entity.Infrastructure.LocalDbConnectionFactory" /> to create connections to LocalDB by default.
/// Requests for <see cref="Func{IDbExecutionStrategy}" /> for the invariant name "System.Data.SqlClient"
/// for any server name are resolved to a delegate that returns a <see cref="DefaultSqlExecutionStrategy" />
/// to provide a non-retrying policy for SQL Server.
Expand Down Expand Up @@ -62,7 +62,7 @@ public sealed class SqlProviderServices : DbProviderServices
// </summary>
private SqlProviderServices()
{
AddDependencyResolver(new SingletonDependencyResolver<IDbConnectionFactory>(new SqlConnectionFactory()));
AddDependencyResolver(new SingletonDependencyResolver<IDbConnectionFactory>(new LocalDbConnectionFactory()));

AddDependencyResolver(
new ExecutionStrategyResolver<DefaultSqlExecutionStrategy>(
Expand Down
4 changes: 2 additions & 2 deletions src/EntityFramework/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Database
// The default factory object used to create a DbConnection from a database name.
private static readonly Lazy<IDbConnectionFactory> _defaultDefaultConnectionFactory =
new Lazy<IDbConnectionFactory>(
() => AppConfig.DefaultInstance.TryGetDefaultConnectionFactory() ?? new SqlConnectionFactory(), isThreadSafe: true);
() => AppConfig.DefaultInstance.TryGetDefaultConnectionFactory() ?? new LocalDbConnectionFactory(), isThreadSafe: true);

private static volatile Lazy<IDbConnectionFactory> _defaultConnectionFactory = _defaultDefaultConnectionFactory;

Expand Down Expand Up @@ -432,7 +432,7 @@ public static bool Delete(DbConnection existingConnection)
/// the context class is passed to this factory in order to generate a DbConnection.
/// By default, the <see cref="IDbConnectionFactory" /> instance to use is read from the application's .config
/// file from the "EntityFramework DefaultConnectionFactory" entry in appSettings. If no entry is found in
/// the config file then <see cref="SqlConnectionFactory" /> is used. Setting this property in code
/// the config file then <see cref="LocalDbConnectionFactory" /> is used. Setting this property in code
/// always overrides whatever value is found in the config file.
/// </remarks>
[Obsolete(
Expand Down
2 changes: 1 addition & 1 deletion src/EntityFramework/DbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace System.Data.Entity
/// is used to find a connection string in the app.config or web.config file. If no connection string is found, then
/// the name is passed to the DefaultConnectionFactory registered on the <see cref="Entity.Database" /> class. The connection
/// factory then uses the context name as the database name in a default connection string. (This default connection
/// string points to .\SQLEXPRESS on the local machine unless a different DefaultConnectionFactory is registered.)
/// string points to (localdb)\MSSQLLocalDB unless a different DefaultConnectionFactory is registered.)
/// Instead of using the derived context name, the connection/database name can also be specified explicitly by
/// passing the name to one of the DbContext constructors that takes a string. The name can also be passed in
/// the form "name=myname", in which case the name must be found in the config file or an exception will be thrown.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public RootDependencyResolver(
_resolvers.Add(new CachingDependencyResolver(defaultProviderServicesResolver));
_resolvers.Add(new CachingDependencyResolver(new DefaultProviderFactoryResolver()));
_resolvers.Add(new CachingDependencyResolver(new DefaultInvariantNameResolver()));
_resolvers.Add(new SingletonDependencyResolver<IDbConnectionFactory>(new SqlConnectionFactory()));
_resolvers.Add(new SingletonDependencyResolver<IDbConnectionFactory>(new LocalDbConnectionFactory()));
_resolvers.Add(new SingletonDependencyResolver<Func<DbContext, IDbModelCacheKey>>(new DefaultModelCacheKeyFactory().Create));
_resolvers.Add(new SingletonDependencyResolver<IManifestTokenResolver>(new DefaultManifestTokenResolver()));
_resolvers.Add(new SingletonDependencyResolver<Func<DbConnection, string, HistoryContext>>(HistoryContext.DefaultFactory));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public sealed class LocalDbConnectionFactory : IDbConnectionFactory
private readonly string _baseConnectionString;
private readonly string _localDbVersion;

/// <summary>
/// Initializes a new instance of the <see cref="LocalDbConnectionFactory"/> class.
/// </summary>
public LocalDbConnectionFactory()
: this("mssqllocaldb")
{
}

/// <summary>
/// Creates a new instance of the connection factory for the given version of LocalDb.
/// For SQL Server 2012 LocalDb use "v11.0".
Expand Down
2 changes: 1 addition & 1 deletion src/EntityFramework/Properties/Resources.PowerShell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ internal static string MigrationsDirectoryParamIsRooted(object p0)
}

// <summary>
// A string like "Failed to add the Entity Framework 'defaultConnectionFactory' entry to the .config file '{0}' in the current project. The default SqlConnectionFactory configured for '.\\SQLEXPRESS' will be used unless you either add the 'defaultConnectionFactory' entry to the .config file manually or specify connection strings in code. See inner exception for details."
// A string like "Failed to add the Entity Framework 'defaultConnectionFactory' entry to the .config file '{0}' in the current project. The default LocalDbConnectionFactory configured for '(localdb)\MSSQLLocalDB' will be used unless you either add the 'defaultConnectionFactory' entry to the .config file manually or specify connection strings in code. See inner exception for details."
// </summary>
internal static string SaveConnectionFactoryInConfigFailed(object p0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/EntityFramework/Properties/Resources.PowerShell.resx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
<value>The 'MigrationsDirectory' parameter was set to the absolute path '{0}'. The migrations directory must be set to a relative path for a sub-directory under the Visual Studio project root.</value>
</data>
<data name="SaveConnectionFactoryInConfigFailed" xml:space="preserve">
<value>Failed to add the Entity Framework 'defaultConnectionFactory' entry to the .config file '{0}' in the current project. The default SqlConnectionFactory configured for '.\\SQLEXPRESS' will be used unless you either add the 'defaultConnectionFactory' entry to the .config file manually or specify connection strings in code. See inner exception for details.</value>
<value>Failed to add the Entity Framework 'defaultConnectionFactory' entry to the .config file '{0}' in the current project. The default LocalDbConnectionFactory configured for '(localdb)\MSSQLLocalDB' will be used unless you either add the 'defaultConnectionFactory' entry to the .config file manually or specify connection strings in code. See inner exception for details.</value>
</data>
<data name="RescaffoldingMigration" xml:space="preserve">
<value>Re-scaffolding migration '{0}'.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public void The_root_resolver_can_return_a_default_model_cache_key_factory()
}

[Fact]
public void The_root_resolver_returns_the_SQL_Server_connection_factory()
public void The_root_resolver_returns_the_LocalDB_connection_factory()
{
Assert.IsType<SqlConnectionFactory>(
Assert.IsType<LocalDbConnectionFactory>(
new RootDependencyResolver().GetService<IDbConnectionFactory>());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ public void GetService_returns_null_for_SQL_generators_for_other_invariant_names
}

[Fact]
public void GetService_resolves_the_default_SQL_Express_connection_factory()
public void GetService_resolves_the_default_LocalDB_connection_factory()
{
Assert.IsType<SqlConnectionFactory>(SqlProviderServices.Instance.GetService<IDbConnectionFactory>());
Assert.IsType<LocalDbConnectionFactory>(SqlProviderServices.Instance.GetService<IDbConnectionFactory>());
}

[Fact]
Expand Down

0 comments on commit 3c927b1

Please sign in to comment.