【发布时间】:2015-12-02 18:35:27
【问题描述】:
我正在尝试构建一个涉及 WCF 服务的解决方案,该服务调用包含 EntityFramework6 模型的 dll。但是,当我尝试对服务进行单元测试时,我收到一条消息:
Additional information: No connection string named 'SyslogEntities' could be found in the application config file.
我的流程在逻辑上安排为:
SyslogDataSvcTest.dll (app.config has service bindings) ->
SyslogDataSvc.svc (web.config has provider and connection string) ->
LibSyslogData.dll (app.config has providers and connection string)
所有涉及 EF 的代码都在 libSyslogData.dll 中。它在内部将数据映射到上层对象,并返回它们,而不是暴露自己的模型信息,所以 EF 的使用应该是真正隔离的。
那我做错了什么?
编辑: 我让它运作良好,但可能以一种奇怪的方式。在安装 EF 和 MySql 依赖项时,NuGet 似乎没有正确指定我的 app.config 中的设置。
相反,我创建了一个代码内配置类,如 MSDN 中所述: https://msdn.microsoft.com/en-us/data/jj680699
现在我有了这个课程:
public class EFConfiguration : DbConfiguration {
public EFConfiguration()
{
//For some reason this works much better than the app.config.
//With this defined, upper layer config documents need only specify the "SyslogEntities" Connection string.
SetExecutionStrategy("MySql.Data.MySqlClient", () => new MySqlExecutionStrategy());
SetDefaultConnectionFactory(new MySqlConnectionFactory());
SetProviderFactory("MySql.Data.MySqlClient", new MySqlClientFactory());
SetProviderServices("MySql.Data.MySqlClient", new MySqlProviderServices());
}
}
我可以将DB实现的细节留给数据层,只在上层配置连接字符串。
【问题讨论】:
标签: c# mysql wcf entity-framework-6