Skip to content

Commit

Permalink
Update ToC (dotnet#4749)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriySvyryd committed Jun 14, 2024
1 parent 76f7505 commit 8e080fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions entity-framework/ef6/what-is-new/microsoft-ef6-sqlserver.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ uid: ef6/what-is-new/microsoft-ef6-sqlserver

# Entity Framework 6 SQL Server provider based on Microsoft.Data.SqlClient

This Entity Framework 6 provider is a replacement provider for the built-in SQL Server provider.
This Entity Framework 6 provider is a replacement provider for the built-in SQL Server provider.

This provider depends on the modern [Microsoft.Data.SqlClient](https://github.com/dotnet/SqlClient) ADO.NET provider, which includes the following advantages over the currently used driver:

Expand Down Expand Up @@ -38,19 +38,24 @@ public class SchoolContext : DbContext
public DbSet<Student> Students { get; set; }
}
````

If you have multiple classes inheriting from DbContext in your solution, add the DbConfigurationType attribute to all of them.

Or you can use the SetConfiguration method before any data access calls:

````csharp
DbConfiguration.SetConfiguration(new MicrosoftSqlDbConfiguration());
````

Or add the following lines to your existing derived DbConfiguration class:

````csharp
SetProviderFactory(MicrosoftSqlProviderServices.ProviderInvariantName, Microsoft.Data.SqlClient.SqlClientFactory.Instance);
SetProviderServices(MicrosoftSqlProviderServices.ProviderInvariantName, MicrosoftSqlProviderServices.Instance);
// Optional
SetExecutionStrategy(MicrosoftSqlProviderServices.ProviderInvariantName, () => new MicrosoftSqlAzureExecutionStrategy());
````

You can also use App.Config based configuration:

````xml
Expand All @@ -60,7 +65,7 @@ You can also use App.Config based configuration:
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<providers>
<providers>
<provider invariantName="Microsoft.Data.SqlClient" type="System.Data.Entity.SqlServer.MicrosoftSqlProviderServices, Microsoft.EntityFramework.SqlServer" />
</providers>
</entityFramework>
Expand All @@ -74,6 +79,7 @@ You can also use App.Config based configuration:
</system.data>
</configuration>
````

If you use App.Config with a .NET 6 or later app, you must remove the `<system.data>` section above and register the DbProviderFactory in code once:

````csharp
Expand Down Expand Up @@ -131,7 +137,7 @@ The following classes have been renamed to avoid conflicts with classes that use

**Azure App Service with .NET Framework and connection strings configuration**

If you use Azure App Service with .NET Framework and the [connection strings configuration feature](https://learn.microsoft.com/azure/app-service/configure-common?tabs=portal#configure-connection-strings), you can encounter runtime issues, as the `ProviderName` connection string setting in this scenario is hardcoded to `System.Data.SqlClient`.
If you use Azure App Service with .NET Framework and the [connection strings configuration feature](/azure/app-service/configure-common?tabs=portal#configure-connection-strings), you can encounter runtime issues, as the `ProviderName` connection string setting in this scenario is hardcoded to `System.Data.SqlClient`.

Solution is to use a derived MicrosoftSqlDbConfiguration class like this:

Expand Down
2 changes: 2 additions & 0 deletions entity-framework/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@
href: ef6/what-is-new/upgrading-to-ef6.md
- name: Visual Studio Releases
href: ef6/what-is-new/visual-studio.md
- name: Microsoft.Data.SqlClient support
href: ef6/what-is-new/microsoft-ef6-sqlserver.md
- name: Get started
href: ef6/get-started.md
- name: Fundamentals
Expand Down

0 comments on commit 8e080fe

Please sign in to comment.