简体   繁体   中英

EntityFrameWork Add function: Unable to load the specified metadata resource

I am using Sql server 2014 and made a ADO.NET Entity Data Model. It generated this model: 在此处输入图片说明

I am trying to add mails I retrieve into my database. It looks like this:

    public int StoreMail(PhishingMail PhishingMail)
    {
        using (var phishingMailStorage = new PhishFinderDB2Entities2())
        {
          //  phishingMailStorage.Database.Connection.Open();

            phishingMailStorage.PhishingMail.Add(PhishingMail);
            phishingMailStorage.SaveChanges();
        }
        return PhishingMail.PhishingMailId;
    }

Whenever I debug the program. I am stuck at this part:

phishingMailStorage.PhishingMail.Add(PhishingMail);

It gives me the metadataexception was unhandeld exception:An unhandled exception of type 'System.Data.Entity.Core.MetadataException' occurred in EntityFramework.dll Additional information: Unable to load the specified metadata resource.

This is my connection string: I really don't know why it generated this gigantic string. It may cause the problem.

<add name="PhishFinderDB2Entities2" connectionString="metadata=res://*/DataAccess.PhishFinderModel.csdl|res://*/DataAccess.PhishFinderModel.ssdl|res://*/DataAccess.PhishFinderModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=WIN7DEV;initial catalog=PhishFinderDB;integrated security=True;pooling=False;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" /><add name="PhishFinderDB2Entities" connectionString="metadata=res://*/DataAccess.PhishFinderModel.csdl|res://*/DataAccess.PhishFinderModel.ssdl|res://*/DataAccess.PhishFinderModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(local);initial catalog=PhishFinderDB2;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /><add name="PhishFinderDB2" connectionString="metadata=res://*/DataAccess.Model1.csdl|res://*/DataAccess.Model1.ssdl|res://*/DataAccess.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=WPNLL0038874\SQLEXPRESS;initial catalog=PhishFinderDB2;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings>

Do you know why I get this exception? Thanks

Try to delete the generated PhishFinderDB2.edmx (keep in mind to save data, if you made your own adjustments). Delete also the connectionstring. Then regenerate the whole PhishFinderDB2 ado.net model. For me this helped multiple times.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM