c# – CodeFirst:在配置中找不到指定的命名连接
发布时间:2020-12-15 07:55:06 所属栏目:百科 来源:网络整理
导读:我创建一个测试项目来测试我的查询,每件事都没问题,除非我尝试测试使用实体连接的方法,我得到以下异常: The specified named connection is either not found in the configuration,not intended to be used with the EntityClient provider,or not valid.
我创建一个测试项目来测试我的查询,每件事都没问题,除非我尝试测试使用实体连接的方法,我得到以下异常:
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的所有方法都可以正常工作并带来除此之外的数据? 解决方法
这不是执行Entity SQL命令的方法.你应该这样做:
// If you have a DbContext instance: var objectContext = ((IObjectContextAdapter)dbContext).ObjectContext; var query = objectContext.CreateQuery<Crop>(eSQL); var result = query.ToList(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |