1

My MyModel.edmx is in the assembly DataAccess.dll. This assembly is referenced in my web project (C#)

My entity connection string is the problem.

This is what I copied from app.config to my win.config:

<add name="MyModelEntities" connectionString="metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=xxx;initial catalog=xxx;persist security info=True;user id=xxx;password=xxx;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

The problem is I am getting error that metadata source can't be loaded.

I am sure that my model name is correct. I have checked dll with Reflector.

So, I am thinking I should include my dll into connection string, and I tried this

<add name="MyModelEntities" connectionString="metadata=res://DataAccess.dll/MyModel.csdl|res://DataAccess.dll/MyModel.ssdl|res://DataAccess.dll/MyModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=xxx;initial catalog=xxx;persist security info=True;user id=xxx;password=xxx;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

But I am getting error that DataAccess.dll can't be find in list of assemblies enumerations.

Is there any way to reference my model inside dll directly. And my dll is not strongly named dll.

Any help is appreciated.

Thanks

bobetko
  • 5,019
  • 14
  • 58
  • 85
  • I find that adding the assembly name to the connection string works for me, but NOT with the .dll extension -- try ...//DataAccess/... rather than ...//DataAccess.dll/.... Of course, * also works for me so you may have a different problem. – JimMat Feb 09 '12 at 02:19
  • I have to say that, so far I started 4-5 projects (with using EF) and this part never went without fight. And I never fixed anything. Things would just start working. I would either recreate project or do something of that kind. And I really feel insecure about this... fell even when working that it might start throwing nonsense error messages at any time... – bobetko Feb 09 '12 at 14:15

2 Answers2

0

I had a similar experience as bobetko, recreating projects and databases with Entity Framework 5 and getting it to work for a while. (VS 2013 Express and SQL Server 2008 R2)

Then, I did this and it fixed all my problems...

To copy model and mapping files to the output directory

  1. Double-click the .edmx file in Solution Explorer.
  2. The file opens in the Entity Designer.
  3. Right-click an empty section of the design surface and select Properties.
  4. The Visual Studio Properties window appears.
  5. Set the value of the Metadata Artifact Processing property to Copy to Output Directory.

http://msdn.microsoft.com/en-us/library/vstudio/cc716709(v=vs.100).aspx

I think VS gets confused by multiple projects in the solution with the multiple connections to the same database. The above fix solved it for me and repaired my broken projects.

maelswarm
  • 1,163
  • 4
  • 18
  • 37
bluesky
  • 150
  • 1
  • 1
  • 11
0

This may not help, but it should clear some things up on how metadata resources work with referenced assemblies.

I ran into the same problem, and after reading JimMat's comment on the original question and a fair bit of trial and error I learned that Entity is picky about it's qualified names in the metadata string.

Make sure the Metadata Artifact Processing (as mentioned by bluesky) is set to Embed in Output Assembly, as this will bake the csdl/ssdl/msl files into the dll for that assembly, and be copied into the bin directory of the referencing project. Rebuild the solution.

  • res:// - tells Entity to look in the project's embedded resources rather than a path to a file on disk
  • ...//*/... - Uses a WildCard for the assembly name
  • .../Namespace.Of.MyModel.csdl - Fully qualified name of the resource, omitting assembly name.

Example: If my DbContext is in a project/assembly called "Data" with a fully qualified name of "Data.Staging.Context," my metadata would look something like

metadata=res://*/Staging.Context.csdl|res://*/Staging.Context.ssdl|...

Or, according to JimMat:

metadata=res://Data/Staging.Context.csdl|res://Data/Staging.Context.ssdl|...
Ryan
  • 1
  • 1
  • 1