EF6, Code-First, enable-migrations, "Unable to load the specified metadata resource"
I had a similar problem but with a different outcome. As it took too many hours to debug, here are some hints.
- The "Unable to load the specified metadata resource." error is related to your connection strings.
- Start by checking the connection string in your project where you have all your entities.
- Make sure the connection string is for a Code First approach and not the Model First or Database First approach (see below for example).
- Repeat these steps in all the projects within your solution where you have a connection string related to your DbContext.
- Then, retry the
Enable-Migrations
command and it should work properly.
Model first connection string example:
<add name="MyContext"
connectionString="metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=MY_DB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
Code first connection string example:
<add name="MyContext"
connectionString="Data Source=.;Initial Catalog=MY_DB;Integrated Security=True;MultipleActiveResultSets=True"
providerName="System.Data.SqlClient"/>
- IF you have more than one project in the solution, be sure that in the Package manager console window you have selected the project with dbContext.
- Migrations use connectionString with name equals DbContext class. In your case it's OrganisationsContext, but isn't Leegz_Entities_Organisations.