【发布时间】:2016-04-06 13:22:33
【问题描述】:
我创建了一个测试项目来测试我的查询,一切正常,除非我尝试测试使用 Entity Connection 的方法,我得到以下异常:
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
我在TestQuery项目中app.config中的连接字符串是我的启动项目:
<connectionStrings>
<add name="DataLayer.Context" connectionString="Data Source=.;Initial Catalog=TestQ;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
所有使用 linq to entity 的方法都可以正常工作并带来除此之外的数据?
【问题讨论】:
-
.不是Data Source的有效值? -
@masa:这是我的本地数据库!
-
请复制和粘贴代码而不是图像。
-
我碰巧看到你提供了赏金。但与此同时,我还没有更清楚我还能为你做些什么。您清楚地在执行 Entity SQL 命令。我向您展示了一种更好的方法,因为实体命令不接受您提供给它的标准连接字符串,只接受一个实体连接字符串(包含元数据),当您使用
objectContext.CreateQuery时您可以免费获得。您没有执行本机 SQL。并且实体命令无法执行原生 SQL。
标签: c# entity-framework unit-testing ef-code-first entity-framework-6