Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeFirst:The specified named connection is either not found in the configuration

I create a Test Project to test my queries , every thing goes okay except when i try to test a method which use Entity Connection ,I get the following exception :

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

enter image description here


My connection string in app.config in the TestQuery Project which is my startup project is:

 <connectionStrings>
    <add name="DataLayer.Context" connectionString="Data Source=.;Initial Catalog=TestQ;Integrated Security=True" providerName="System.Data.SqlClient"/>
 </connectionStrings>

All the methods which use linq to entity works just fine and brings the data except this one ?

like image 562
Anyname Donotcare Avatar asked Jan 02 '16 11:01

Anyname Donotcare


1 Answers

This is not the way to execute an Entity SQL command. You should do this instead:

// If you have a DbContext instance:
var objectContext = ((IObjectContextAdapter)dbContext).ObjectContext;
var query = objectContext.CreateQuery<Crop>(eSQL);
var result = query.ToList();
like image 89
Gert Arnold Avatar answered Nov 17 '22 07:11

Gert Arnold