Entity Framework 6 Error Unable to load the specified metadata resource
Asked Answered
P

3

18

I'm using Entity Framework 6 and "model first" in my solution, I separated my "Data Model" classes into another project, so that I can add reference to the "Data Model" classes without exposing my "Data Model Contexts" and connections. I don't want to expose my Entity Data Model project (especially the DB Context etc) to my UI Layer. I have this:

enter image description here

I have now successfully separated my auto generated entity classes from my data model, I tried it this works by adding an entity or a property to an entity is updated in the project Mapeo.BusinessEntity.

This is my connection string from DatabaseLayer (Mapeo.DatabaseModel)

<connectionStrings>
   <add name="MapeoModelContainer" connectionString="metadata=res://*/MapeoModel.csdl|res://*/MapeoModel.ssdl|res://*/MapeoModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=raranibar\ral;initial catalog=Mapeo;user id=sa;password=*****;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

In my service layer I it copied this connection string to the App.config, my problem is this when I want to add a data I have this message: Unable to load the specified metadata resource How I can resolve this problem?

enter image description here

Updated I found the solution, I changed the connectionstring in App.Config the pretentation layer I replaced in the connection strign "*" for the directory of DataModel in my case (Mapeo.DatabaseModel) this is now my connection string in layer presentation:

  <connectionStrings>
     <add name="MapeoModelContainer" connectionString="metadata=res://Mapeo.DatabaseModel/MapeoModel.csdl|res://Mapeo.DatabaseModel/MapeoModel.ssdl|res://Mapeo.DatabaseModel/MapeoModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=raranibar\ral;initial catalog=Mapeo;user id=sa;password=scugua;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
Peshawar answered 26/8, 2014 at 20:45 Comment(8)
Have you changed the connectionstring?Puss
This SO question might help: #689855Puss
@Puss I haven't changed the connectionstring, it is the same that is in my Mapeo.DatabaseModelPeshawar
The error does mean the Edmx cannot be loaded. Does the presentation layer have a ref to the data layer?Puss
@jaywayco, yes in my presentation layer I have a ref to the data layerPeshawar
updating the metadata in connection string to appropriate relative URL worked!!!Pieeyed
But you only need one app.config connection string though(From the calling application?), and not two as you explained(One in UI and one in Data layer)Timofei
Suggest you to please post the update in your post as an answer to this question (also accept that as answer) so that community can focus on other unanswered question. This question keeps featuring in unanswered question even though it seems you were able to solve it yourself.Gimel
F
4

Update your connectionString with correct path if you've such like issue to load metadata files. May it help someone else...

connectionString="metadata=res://DatabaseModel/MyModel...
Floatage answered 16/7, 2016 at 15:38 Comment(1)
99 times out of 100, if I have this issue, this is the cause. The connectionstring needs to reflect the correct metadata.Previse
T
3

When you copy an EDMX from one project to another, you must be careful with the name of the folder where you originally created the EDMX, because it's reflected in the app.config (or web.config), in the connection string related to the metadata resource. Like this:

//Initial model created in Folder1 in the original project
<add name="DataModelContainer" connectionString="metadata=res://*/Folder1.ServerModel.csdl|res://*/Folder1.ServerModel.ssdl|res://*/Folder1.ServerModel.msl;provider=System.Data.SqlClient;provider connection string= .../>

//Then manually copied to Folder2 in other project
<add name="DataModelContainer" connectionString="metadata=res://*/Folder2.ServerModel.csdl|res://*/Folder2.ServerModel.ssdl|res://*/Folder2.ServerModel.msl;provider=System.Data.SqlClient;provider connection string= .../>
Thoroughfare answered 20/6, 2021 at 15:8 Comment(0)
J
0

After creating the entity if the database edit, entity does not work

As long as the entity update

In this way:

enter image description here

If this method did not work

It is better to do:

  1. Remove this tag: <add name="MapeoModelContainer" ...
  2. Remove MapeoModel.edmx
  3. Add ADO.NET Entity Data Model

Then use the wizard to create a connection and entity

If this method did not work either send Inner exception

Jeanne answered 15/2, 2017 at 19:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.