ErikEJ.EntityFramework.SqlServer 6.6.4

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
.NET Standard 2.1 .NET Framework 4.6.2

Requires NuGet 5.0 or higher.

dotnet add package ErikEJ.EntityFramework.SqlServer --version 6.6.4
NuGet\Install-Package ErikEJ.EntityFramework.SqlServer -Version 6.6.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ErikEJ.EntityFramework.SqlServer" Version="6.6.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ErikEJ.EntityFramework.SqlServer --version 6.6.4
#r "nuget: ErikEJ.EntityFramework.SqlServer, 6.6.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ErikEJ.EntityFramework.SqlServer as a Cake Addin
#addin nuget:?package=ErikEJ.EntityFramework.SqlServer&version=6.6.4

// Install ErikEJ.EntityFramework.SqlServer as a Cake Tool
#tool nuget:?package=ErikEJ.EntityFramework.SqlServer&version=6.6.4

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 provider depends on the modern Microsoft.Data.SqlClient ADO.NET provider, see my blog post here for why that can be desirable.

The latest build of this package is available from NuGet

Configuration

There are various ways to configure Entity Framework to use this provider.

You can register the provider in code using an attribute:

    [DbConfigurationType(typeof(MicrosoftSqlDbConfiguration))]
    public class SchoolContext : DbContext
    {
        public SchoolContext() : base()
        {
        }

        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:

 DbConfiguration.SetConfiguration(new MicrosoftSqlDbConfiguration());

Or you can add the following lines to your existing DbConfiguration class:

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

You can also use XML/App.Config based configuration:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <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>		
            <provider invariantName="Microsoft.Data.SqlClient" type="System.Data.Entity.SqlServer.MicrosoftSqlProviderServices, ErikEJ.EntityFramework.SqlServer" />
        </providers>
    </entityFramework>
    <system.data>
        <DbProviderFactories>
           <add name="SqlClient Data Provider"
             invariant="Microsoft.Data.SqlClient"
             description=".NET Framework Data Provider for SqlServer"
             type="Microsoft.Data.SqlClient.SqlClientFactory, Microsoft.Data.SqlClient" />
        </DbProviderFactories>
    </system.data>
</configuration>

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

DbProviderFactories.RegisterFactory(MicrosoftSqlProviderServices.ProviderInvariantName, Microsoft.Data.SqlClient.SqlClientFactory.Instance);

EDMX usage

If you use an EDMX file, update the Provider name:

<edmx:Edmx Version="3.0" xmlns:edmx="http://schemas.microsoft.com/ado/2009/11/edmx">
  <edmx:Runtime>
    <edmx:StorageModels>
      <Schema Namespace="ChinookModel.Store" Provider="Microsoft.Data.SqlClient" >

In order to use the EDMX file with the Visual Studio designer, you must switch the provider name back to System.Data.SqlClient

Also update the provider name inside the EntityConnection connection string:

 <add 
    name="Database" 
    connectionString="metadata=res://*/EFModels.csdl|res://*/EFModels.ssdl|res://*/EFModels.msl;provider=Microsoft.Data.SqlClient;provider connection string=&quot;data source=server;initial catalog=mydb;integrated security=True;persist security info=True;" 
    providerName="System.Data.EntityClient" 
 />

Code changes

In order to use the provider in an existing solution, a few code changes are required (as needed).

using System.Data.SqlClient;using Microsoft.Data.SqlClient;

The following classes have been renamed to avoid conflicts with classes in the existing SQL Server provider:

SqlAzureExecutionStrategyMicrosoftSqlAzureExecutionStrategy

SqlConnectionFactoryMicrosoftSqlConnectionFactory

SqlDbConfigurationMicrosoftSqlDbConfiguration

SqlProviderServicesMicrosoftSqlProviderServices

SqlServerMigrationSqlGeneratorMicrosoftSqlServerMigrationSqlGenerator

SqlSpatialServicesMicrosoftSqlSpatialServices

Known issues

EntityFramework.dll installed in GAC

If an older version of EntityFramework.dll is installed in the .NET Framework GAC (Global Assembly Cache), you might get this error:

The 'PrimitiveTypeKind' attribute is invalid - The value 'HierarchyId' is invalid according to its datatype

Solution is to remove the .dll from the GAC, see this for more info

Feedback

Please report any issues, questions and suggestions here

Release notes

6.6.4

  • Fix wrong resource reference (to old provider assembly)

6.6.3

  • Uses Microsoft.Data.SqlClient 5.1.0

6.6.2

  • Uses Microsoft.SqlServer.Types 160.1000.6
  • Requires .NET Framework 4.6.2

6.6.1

  • Uses Microsoft.Data.SqlClient 5.0.1

6.6.0

  • Uses Microsoft.Data.SqlClient 5.0.0
  • Added support for spatial on .NET (Core) with new Microsoft.SqlServer.Types package

6.5.0

  • Uses Microsoft.Data.SqlClient 4.0.1
  • Removed duplicate spatial and Sql functions classes

6.4.x

  • Uses Microsoft.Data.SqlClient 2.1.4
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.1
.NET Framework net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ErikEJ.EntityFramework.SqlServer:

Package Downloads
SonicGD.EntityFramework.BulkExtensions

Bulk operations extension library for Entity Framework.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.6.4 3,105 2/9/2023
6.6.3 3,225 1/20/2023
6.6.2 10,106 11/24/2022
6.6.0 9,247 9/8/2022
6.6.0-rc1 66 9/5/2022
6.5.0 813 9/4/2022
6.5.0-rc1 249 8/9/2022
6.4.3 44,078 3/24/2022
6.4.2 638 3/12/2022
6.4.1 65,821 12/12/2021
6.4.1-preview1 121 11/27/2021
6.4.0 51,175 8/24/2021
1.0.0-rc5 475 8/19/2021

Fix wrong resource reference