Any*_*are 7 c# unit-testing entity-framework ef-code-first entity-framework-6
我创建一个测试项目来测试我的查询,每件事情都没关系,除非我尝试测试一个使用的方法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.
Run Code Online (Sandbox Code Playgroud)
我app.config在TestQuery项目中的连接字符串是我的启动项目:
<connectionStrings>
<add name="DataLayer.Context" connectionString="Data Source=.;Initial Catalog=TestQ;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
使用linq to entity的所有方法都可以正常工作并带来除此之外的数据?
这不是执行Entity SQL命令的方法.你应该这样做:
// If you have a DbContext instance:
var objectContext = ((IObjectContextAdapter)dbContext).ObjectContext;
var query = objectContext.CreateQuery<Crop>(eSQL);
var result = query.ToList();
Run Code Online (Sandbox Code Playgroud)