4

So I have set up a SQL Server and EF in my project.

MPSDBEntities mpsEntities = new MPSDBEntities();

And it works fine when I do a save changes. e.g

mpsEntities.SaveChanges();

it updates the database (does it mean my connection string is correct?)

However, whenever I tried to perform any kind of load data/SQL from the EF, such as

var temp = mpsEntities.CARD_BY_CHECKTYPE.Where(x => (x.CHECK_TYPE == "AA2")).ToList();

It would throw an exception of

Unable to Load the specified metadata resource.

Here is my connection string, which I doubt is where the problem is at:

<add name="MPSDBEntities" 
     connectionString="metadata=res://*/MPSDBModel.csdl|res://*/MPSDBModel.ssdl|res://*/MPSDBModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=PAE0DT-DDWB282\MPS2;initial catalog=MPS;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />

I went through the following posts. They didn't solve my problem.

System.Data.MetadataException: Unable to load the specified metadata resource

MetadataException: Unable to load the specified metadata resource

Entity Framework: Unable to load the specified metadata resource

Unable to load the specified metadata resource

Anyone know what the problem is? Thank you.

@petryuno1

Here is my DbContext, if this is what you are asking..

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

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

    public virtual DbSet<CARD_BY_CHECKTYPE> CARD_BY_CHECKTYPE { get; set; }
    ........
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Heisenberg
  • 764
  • 6
  • 20

1 Answers1

1

This worked for me.

Changing from this:

connectionString="metadata=res://*/Model.Project.csdl|res://*/Model.Project.ssdl|res://*/Model.Project.msl;

change to:

connectionString="metadata=res://*/;

And add the rest of your connection string after. Hope it helps.

Adam Lee
  • 66
  • 1
  • 15
  • Tried. Still yelled at me the same error message. But thanks anyway! – Heisenberg Mar 12 '18 at 20:57
  • Have you check both the "App.config" and the "Web.config"? – Adam Lee Mar 12 '18 at 21:02
  • Thank you..I don't see a Web.config in my solution explorer.....Sorry i didn't put this as a C# WPF project other than an ASP.NET.... – Heisenberg Mar 12 '18 at 21:10
  • There is nothing wrong with your connection string, have you tried another select query? – Adam Lee Mar 12 '18 at 21:19
  • Thank you for your help. Yes. I've tried even the simplest ones such as var temp = mpsEntities.CARD_BY_CHECKTYPE.ToList(); Didn't work neither. But var temp = mpsEntities.CARD_BY_CHECKTYPE without ToList() didn't give me that Unable to Load the specified metadata resource exception though. – Heisenberg Mar 12 '18 at 21:27