Skip to main content

SQL Server Compact provider for Entity Framework 6.4 on Windows

Total Downloads
10.1K
10,144
Published
Sep 5, 2023
3y ago

Get Started

dotnet add package ErikEJ.EntityFramework.SqlServerCompact --version 6.4.0-beta5
ProductVersions
.NET
net6.0

README

Entity Framework 6 SQL Server Compact provider for .NET 6 (and later)

This Entity Framework provider includes everything required to start creating and using a SQL Server Compact embedded database with Entity Framework 6.

You can read more about using the SQL Server Compact ADO.NET provider with .NET Core in my blog post here

Getting started

Add a PackageReference like this to use the latest preview build:

<ItemGroup>
    <PackageReference Include="ErikEJ.EntityFramework.SqlServerCompact" Version="6.4.0-*" />
</ItemGroup>

Provider 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(SqlCeDbConfiguration))]
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 SqlCeDbConfiguration());

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

SetProviderFactory(SqlCeProviderServices.ProviderInvariantName, SqlServerCe.SqlCeProviderFactory.Instance);
SetProviderServices(SqlCeProviderServices.ProviderInvariantName, SqlCeProviderServices.Instance);

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="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServer.SqlCeProviderServices, ErikEJ.EntityFramework.SqlServerCompact" />
    </providers>
  </entityFramework>
</configuration>

If you use App.Config with a .NET app, you must register the DbProviderFactory in code once:

DbProviderFactories.RegisterFactory(SqlCeProviderServices.ProviderInvariantName, SqlServerCe.SqlCeProviderFactory.Instance);

Feedback

Please report any issues, questions and suggestions here

Downloads by Version

Similar & Alternative Packages

Hand-picked matching NuGet libraries based on tags & ecosystem

Depended On By

Find packages that declare this package as a dependency. NuGet does not provide a reverse-dependency endpoint, so candidates are checked on demand.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 1 target framework; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.