Entity Framework Error unable to load the specified metadata resource

user6321478 picture user6321478 · Jun 4, 2016 · Viewed 7.3k times · Source

Yes I did read and try entity framework Unable to load the specified metadata resource

I typically use code first and have had no issues. However I needed to troubleshoot a project with EDMX

Context:

public partial class x500Entities : DbContext
{
    public x500Entities()
        : base("name=x500Entities")
    {
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        throw new UnintentionalCodeFirstException();
    }

    public virtual DbSet<WorkerPublicExtended> WorkerPublicExtendeds { get; set; }
}

connection string :

<add name="x500Entities"
connectionString="metadata=res://*/CDISWorkerPublicExtended.csdl|res://*/CDISWorkerPublicExtended.ssdl|res://*/CDISWorkerPublicExtended.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=xserver;initial catalog=x500;persist security info=True;user id=xuser;password=xpassword;MultipleActiveResultSets=True;App=EntityFramework&quot;"
providerName="System.Data.EntityClient"/>

ERROR :

An exception of type 'System.Data.Entity.Core.MetadataException' occurred in EntityFramework.dll but was not handled in user code Additional information: Unable to load the specified metadata resource.

Upon hitting this line:

return context.WorkerPublicExtendeds.FirstOrDefault(x => x.upperIDSID == idsid.ToUpper().Trim());

Complete Method :

 public WorkerPublicExtended GetEmployee(string idsid)
 {
     using (x500Entities context = new x500Entities())
     {
         return context.WorkerPublicExtendeds.FirstOrDefault(x => x.upperIDSID == idsid.ToUpper().Trim());
     }
 }
  1. Why is this happening?
  2. I connected to sql server ssms and I don't see the table WorkerPublicExtended that I have seen in diagram edmx and the model, I don't see where that name is translated to a real table name. How is this?

Answer

njasm picture njasm · Jun 4, 2016

Probable causes: 1) your resource file is nowhere to be found in you project (this resource file is configured in you app.config in connection string) confirm oyu have it.

2) when you say you connect to the database and you don't see the Table then you're in the wrong database? that should never happen, you have an EDMX generated for another database, or someone droped the table and didn't regenerate the edmx ? :X

If you have 200% sure that the database you are connecting it's the latest in schema, procedures, views, etc, or it's the production database, why not to delete the entire edmx and recreate, test and redeploy?