开发者

referencing edmx in mvc project

I have a EF connection string in an MVC project like so:

connectionString="metadata=res:///Models.db.csdl|res:///Models.db.ssdl|res://*/Models.db.msl;provider=System.Data.SqlClient;provider connection string="Data Source=localhost;Initial Catalog=SystemName;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient"

All is well until I added a second project and referenced the MVC project that contains the edmx, but during runtime I get:

The specified metadata path is not valid. A valid path开发者_开发知识库 must be either an existing directory, an existing file with extension '.csdl', '.ssdl', or '.msl', or a URI that identifies an embedded resource.

I've read post after post, but I can't figure out how to correctly reference the metadata in the MVC project. Can someone point me in the correct direction? I don't want to create a connection string that is so specific it breaks during deployment and debug.


The format for resources is:

Metadata=res://<assemblyFullName>/<resourceName>. 

The lazy way is to use a wild card res://*/bah.msl. Which would load the model/mapping files from the bin directory, calling assembly, as well as referenced assemblies.

In your case:

res:///Models.db.csdl|res:///Models.db.ssdl|res://*/Models.db.msl

Is incorrect, try:

res://*/Models.db.csdl|res://*/Models.db.ssdl|res://*/Models.db.msl

Complete string:

connectionString="metadata=res://*/Models.db.csdl|res://*/Models.db.ssdl|res://*/Models.db.msl;provider=System.Data.SqlClient;provider connection string='Data Source=localhost;Initial Catalog=SystemName;Integrated Security=True;MultipleActiveResultSets=True'" providerName="System.Data.EntityClient"

Alternatively you could use absolute references which is faster(but I am assuming this will be much more painful for you):

Metadata=res://<DLL>, <Version>, neutral, <SN>/Models.db.csdl|Models.db.ssdl|Models.db.msl
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜