Entity Framwork Unable to Load the specified metadata resource

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. eg

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-DDWB282MPS2;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; }
    ........
}

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.

链接地址: http://www.djcxy.com/p/38810.html

上一篇: 有没有办法检查一个文件是否在使用?

下一篇: 实体框架无法加载指定的元数据资源