Entity Framework: How to embed C/M/S Files

That’s simple:

  1. Embed your files as a resource in your DLL
  2. In your app.config change the connectionstring from:

<add name="KistlContext"
  connectionString="metadata=.\Model.csdl|.\Model.ssdl|.\Model.msl;
  provider=System.Data.SqlClient;
  provider connection string='Data Source=.\SQLEXPRESS;
    Initial Catalog=YourDatabase;
    Integrated Security=True;
    MultipleActiveResultSets=true;'"
  providerName="System.Data.EntityClient" />

to:


<add name="KistlContext"
  connectionString="metadata=res://*;
  provider=System.Data.SqlClient;
  provider connection string='Data Source=.\SQLEXPRESS;
    Initial Catalog=YourDatabase;
    Integrated Security=True;
    MultipleActiveResultSets=true;'"
  providerName="System.Data.EntityClient" />

It does not matter in which assembly the model is embedded.

Leave a Reply