Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am having some serious problems with Entity Framework and I can't seem to figure out whats going on.

I tried many options provided on: MetadataException: Unable to load the specified metadata resource and the famous Craig Stuntz's blog posting located at: http://blogs.teamb.com/craigstuntz/2010/08/13/38628/

I have 3 projects for the sake of brevity:

Funscribe.Data (EDMX file located here)

Funscribe.Console (Console app)

Funscribe.Web (MVC 3 app)

Originally it was just the MVC app and I recently added this new console project.

I copied the connection string from web.config and applied it to my app.config:

<add name="FundirectoryEntities" connectionString="metadata=res://*/Fundirectory.csdl|res://*/Fundirectory.ssdl|res://*/Fundirectory.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhostsqlexpress;initial catalog=Funscribe;user id=sys_Funscribe;password=blah;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />

My mvc app continues to work, but when I run the console app, i get the dreaded:

"Unable to load the specified metadata resource."

I tried changing the connection string to the wild card setting:

<add name="FundirectoryEntities" connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhostsqlexpress;initial catalog=Funscribe;user id=sys_Funscribe;password=blah;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />

I get: The specified default EntityContainer name 'FundirectoryEntities' could not be found in the mapping and metadata information.

I tried changing it to specify the assembly:

<add name="FundirectoryEntities" connectionString="metadata=res://Funscribe.Data.dll/Fundirectory.csdl|res://Funscribe.Data.dll/Fundirectory.ssdl|res://Funscribe.Data.dll/Fundirectory.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhostsqlexpress;initial catalog=Funscribe;user id=sys_Funscribe;password=blah;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />

I get: Unable to resolve assembly 'Funscribe.Data.dll'.

I am lost on what I should do here. I just upgraded this project to Visual Studio 2012 (I introduce this new console app after converting to VS 2012).

I also noticed that the Funscribe.Data.dll is located within the console project's bin folder, i manually deleted these files and watch it get recreated. And what puzzles me is the web app continues to work properly!

All projects are on .NET 4.0. The console app uses .NET 4.0 not the client profile verison.

Any help on this matter is greatly appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
599 views
Welcome To Ask or Share your Answers For Others

1 Answer

The metadata parameter for an application with an Entity Framework model called Model.edmx in an assembly called Simple Mvc.Data.dll might look like this:

<connectionStrings>
    <add name="MyEntities" connectionString="metadata=
            res://Simple Mvc.Data.dll/Model.csdl|
            res://Simple Mvc.Data.dll/Model.ssdl|
            res://Simple Mvc.Data.dll/Model.msl;provider= <!-- ... -->

So you can see there is one reference for each of the three parts of the EDMX that we need at runtime. They all work in the same way, so let’s examine just the first more closely. The CSDL reference looks like this:

        res://Simple Mvc.Data.dll/Model.csdl

It specifies three things:

  • We’re loading the CSDL from a resource. That’s the "res://" part.

  • The name of the assembly which contains the resource, "Simple Mvc.Data.dll". If your assembly is strong named, you can specify a strong name, in all its verbose glory, here.

  • The name of the resource itself, "Model.csdl". Do not confuse this with the EDMX or model name. In this case they happen to be the same, except for the extension, but that’s not always true!

It will probably fail if your resources don’t happen to have the same name as your model, or if the assembly doesn’t happen to be loaded.

For more information check this out Troubleshooting Entity Framework Connection Strings

I hope this will help to you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...