2

When I try and use EntityFramework and MySQL on a Linux or Windows environment I run into the following problem:

Project 1: Contains EntityFramework edmx and logic to insert update data using the dbcontext class Project 2: References Project 1.

When I build the solution using msbuild the EntityFramework metadata files are embeded in Project1.dll

enter image description here

When I do a clean build with xbuild in a Linux environment or in a Windows environment the EntityFramework metadata files are missing

enter image description here

When you run the application you get the following error:

Unable to load the specified metadata resource.

I am using mono version 4.2.2

Does anybody know a solution for embedding the EntityFramework metadata files when using xbuild?

Tjaart van der Walt
  • 5,149
  • 2
  • 30
  • 50

1 Answers1

3

I have implemented the following workaround until mono embeds the Entity Framework metadata artifacts

  1. Step1 - Update your EntityFramework Model's Metadata Artifact Processing property from "Embed in Output Assembly" to "Copy to Output Directory"

enter image description here

This copies the metadata artifact files to the bin folder of the project containing the .edmx(Project1)

  1. Step2 - Add the following post build events to the referencing project(Project2) to copy the metadata artifact files to its bin. You can add them to the end of the .csproj project file. Replace Project1 with the name of your project.

    <PropertyGroup>
       <PostBuildEvent Condition=" '$(OS)' != 'Unix' ">copy /Y   "$(ProjectDir)..\Project1\bin\Debug\Models\*" "$(ProjectDir)\bin\Debug\"  </PostBuildEvent>
       <PostBuildEvent Condition=" '$(OS)' == 'Unix' ">cp -a "$(ProjectDir)../Project1/bin/Debug/Models/." "$(ProjectDir)bin/Debug/"  </PostBuildEvent>
    </PropertyGroup>
    
  2. Step3 - Update your connection string

    from

    <add name="EntityframeworkTestEntities" connectionString="metadata=res://*/EntityFrameworkTestModel.csdl|res://*/EntityFrameworkTestModel.ssdl|res://*/EntityFrameworkTestModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=EntityframeworkTest;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    

    to

    <add name="EntityframeworkTestEntities" connectionString="metadata=EntityFrameworkTestModel.csdl|EntityFrameworkTestModel.ssdl|EntityFrameworkTestModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=EntityframeworkTest;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    
Tjaart van der Walt
  • 5,149
  • 2
  • 30
  • 50