我在app.config中设置正确的元数据res时遇到问题。
我正在创建提供数据库访问权限的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.
何时使用元数据文件的绝对路径,一切正常。有谁知道,问题是什么?
感谢。此致
答案 0 :(得分:0)
最后我找到了解决方案。我正在将Environment.CurrentDirectory更改为目录,从中安装了服务。
我用过:XML file couldn't be detected after windows service setup
此致