【发布时间】:2014-01-18 18:45:07
【问题描述】:
我在 app.config 中设置正确的元数据资源时遇到问题。
我正在创建提供对数据库的访问的 WCF 服务器应用程序。
我的 ssdl、msl 和 csdl 文件位于 Assembly/EntityModel/...
当我在控制台应用程序中托管此 WCF 服务器时,我的连接字符串如下所示:
<add name="xpdir2ModelContainer" connectionString="metadata=.\EntityModel\xpdir2Model.csdl|.\EntityModel\xpdir2Model.ssdl|.\EntityModel\xpdir2Model.msl;provider=Npgsql;provider connection string="Port=5432;Encoding=WIN1250;Server=localhost;Database=xpdir2_mvc;UserId=postgres;Password=postgres"" providerName="System.Data.EntityClient"/>
一切正常。在我将主机从控制台应用程序更改为 Windows 服务后,它停止工作。我知道,当我安装服务时,它的当前目录类似于 Windows/Wow64/...
所以我试图将元数据文件设置为嵌入式资源。我用:
<add name="xpdir2ModelContainer" connectionString="metadata=res://*/EntityModel.xpdir2Model.csdl|res://*/EntityModel.xpdir2Model.ssdl|res://*/EntityModel.xpdir2Model.msl;provider=Npgsql;provider connection string="Port=5432;Encoding=WIN1250;Server=localhost;Database=xpdir2_mvc;UserId=postgres;Password=postgres"" providerName="System.Data.EntityClient"/>
但这不起作用。它抛出异常:
{System.Data.MappingException: Schema specified is not valid. Errors:
EntityModel.xpdir2Model.msl(5,4) : error 2062: No mapping specified for instances of the EntitySet and AssociationSet in the EntityContainer xpdir2ModelContainer.
当使用元数据文件的绝对路径时,一切正常。有谁知道,是什么问题?
谢谢。问候
【问题讨论】:
标签: c# entity-framework metadata