Available Presets

For Entity Framework v5 and v6, the following presets are available. Every preset generates all entity classes, typed list row classes, typed view row classes and value type classes in separate files and adds proper XML comments to the generated code.

All presets generate a DbContext class called ProjectNameDataContext, unless the setting SetContextClassNameEqualToEdmxModelContainerName is set to true, the context class is then called ProjectNameEntities.

The presets are similar to the Proxy friendly POCO entities for Entity Framework v4, however instead they generate a DbContext using context class, and plain classes for entities, no tracking code whatsoever is added as it's not required.

All presets generate two VS.NET projects. The first VS.NET project, called RootNamespace.Model and located in the Model folder, contains the entity classes, value type classes, typed list row classes and typed view row classes.

The second VS.NET project, called RootNamespace.Persistence and located in the Persistence folder, contains the DbContext class and either the EDMX file (DbContext API preset) or the ModelBuilder class (Code First preset).

For Entity Framework v6

.NET Framework

These presets generate code targeting the .NET Framework version you select.

  • SD.EntityFramework.v6 (DbContext API). This is the default.
  • SD.EntityFramework.v6 (Code First). This preset generates a ModelBuilder class instead of an EDMX file, for code first support.

.NET Standard 2.1

These presets generate code targeting .NET Standard 2.1 and can be used on .NET Core 3.0+ and other frameworks implementing .NET Standard 2.1.

  • SD.EntityFramework.v6 (DbContext API, Netstandard).
  • SD.EntityFramework.v6 (Code First, Netstandard). This preset generates a ModelBuilder class instead of an EDMX file, for code first support.

Limitations of Entity Framework v6 on .NET Standard 2.1

If you opt for using the .NET Standard 2.1 target there are some limitations on what's supported for Entity Framework v6.

  • Spatial types are currently not supported (Microsoft.SqlServer.Types), as the required package isn't supported on .NET Core
  • When using an EDMX file, you need to alter the generated connectionstring, if you pass it as a string to the DbContext constructor:

Generated app.config:

<?xml version="1.0" encoding="utf-8" ?>
        <!-- please adjust the connection string embedded in the element below to target the proper catalog / server using the proper user / password combination -->
        <add name="ConnectionString.SQL Server (SqlClient)" connectionString="metadata=res://*/mymodel.csdl|res://*/mymodel.ssdl|res://*/mymodel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=myserver;initial catalog=mymodeldb;integrated security=SSPI;persist security info=False&quot;" providerName="System.Data.EntityClient" />

To use this connection string on .NET Core in a class library package, you can't rely on the app/web.config file to be there, you have to pass the connectionstring as a string to the DbContext class, and you have to change the &quot; fragments to \". So the above connection string becomes:

string connectionString = "metadata=res://*/mymodel.csdl|res://*/mymodel.ssdl|res://*/mymodel.msl;provider=System.Data.SqlClient;provider connection string=\"data source=myserver;initial catalog=mymodeldb;integrated security=SSPI;persist security info=False\"";

// to use it...
using(var ctx = new MyModelDataContext(connectionString))

For Entity Framework v5

  • SD.EntityFramework.v5 (DbContext API)

Compiling and using the generated code

To use both generated VS.NET projects in your own solution, be sure that the RootNamespace.Persistence VS.NET project references the RootNamespace.Model VS.NET project. For Entity Framework v5, the generated code will reference the Entity Framework assembly shipped with VS.NET.

For Entity Framework v6, in the RootNamespace.Persistence VS.NET project you have to add a reference to the Entity Framework v6 assembly available on nuget. This will make sure you'll reference the Entity Framework version matching the .NET version you're targeting.