DEV Community

Christoph Weigert
Christoph Weigert

Posted on • Originally published at christophweigert.com on

Reuse EDMX files with .NET Core or .NET Standard 2.1

Reuse EDMX files with .NET Core or .NET Standard 2.1

If you previously an EDMX file for your database first model generation you are left out for .NET Standard or .NET Core Support. But there is at least a workaround that you can use to target .NET Standard 2.1 or .NET Core Apps with 3.0 or newer.

You have to create a separate project and link your EDMX, Context and Model files. This solutions works independently of C# or VB.NET. The magic lies in the build action "EntityDeploy" introduced with Entity Framework 6.3. Updating the model needs to be done in the .NET Framework project.

This is project file I created. Feel free to reuse it but change vb to cs in case you want to use it with a C# model.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>netstandard2.1;net472</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="EntityFramework" Version="6.4.0" />
  </ItemGroup>

  <ItemGroup>
    <EntityDeploy Include="..\Test.EntityFramework\YourEdmx.edmx" Link="YourEdmx.edmx" />
    <Compile Include="..\Test.EntityFramework\YourEdmx.Context.vb" Link="sbEntities.Context.vb" />
    <Compile Include="..\Test.EntityFramework\Employee.vb" Link="Employee.vb" />
  </ItemGroup>

</Project>

If you have many model classes you can use a neat feature or visual studio. Right-click inside your new project and click "Add > existing item"

Reuse EDMX files with .NET Core or .NET Standard 2.1
Before manually modifying your project file you can use the "Add As Link" feature from Visual Studio.

For further reference you can see the Microsoft Documentation, GitHub Issue or the sample repository.

Top comments (0)