简体   繁体   English

EntityFrameWork Add函数:无法加载指定的元数据资源

[英]EntityFrameWork Add function: Unable to load the specified metadata resource

I am using Sql server 2014 and made a ADO.NET Entity Data Model. 我正在使用Sql Server 2014,并制作了ADO.NET实体数据模型。 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. 它给了我metadataexception是不可处理的异常:EntityFramework.dll中发生了类型为'System.Data.Entity.Core.MetadataException'的未处理的异常。其他信息:无法加载指定的元数据资源。

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). 尝试删除生成的PhishFinderDB2.edmx (如果进行了自己的调整,请记住要保存数据)。 Delete also the connectionstring. 还要删除连接字符串。 Then regenerate the whole PhishFinderDB2 ado.net model. 然后重新生成整个PhishFinderDB2 ado.net模型。 For me this helped multiple times. 对我来说,这帮助了很多次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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