I have an n-layered application with data base activity performed in my data access layer. I have an application layer which asks my data access layer to perform tasks from the repositories in the data access layer. My user interface, which for now is a simple console app to test results, asks my application layer to get things like a list of data which in turn the application layer gets from the repository and it all gets back to the console app.
If I don't add the entity framework as a reference in my console app, I get the following error:
The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
Why am I getting this error when the console app makes no data access calls or entity framework operations? All that is done in my data access layer which does have Entity Framework referenced.
Update: Below is my console interface:
class MyServices
{
IProductRequestServices _ProductRequestServices;
public MyServices(IProductRequestServices _ProductRequestServices)
{
this._ProductRequestServices = _ProductRequestServices;
}
public void ProductList()
{
List<ProductRequestDetailDto> aList = _ProductRequestServices.GetProductRequestExtendedDetailAll();
foreach (ProductRequestDetailDto prodReq in aList)
{
System.Console.WriteLine("Product Req ID: {0} - Product Name: {1}",
prodReq.productRequestId.ToString(), prodReq.productName);
}
}
public void ClientList()
{
List<ProductRequestDetailDto> aList = _ProductRequestServices.GetProductRequestExtendedDetailAll();
foreach (ProductRequestDetailDto prodReq in aList)
{
System.Console.WriteLine("Product Req ID: {0} - Product Name: {1}",
prodReq.productRequestId.ToString(), prodReq.firstName + " " + prodReq.lastName);
}
}
}
class Program
{
static void Main(string[] args)
{
ProductRequestServices _ProductRequestServices = new ProductRequestServices();
MyServices MyServices = new MyServices(_ProductRequestServices);
MyServices.ProductList();
System.Console.WriteLine("============================");
MyServices.ClientList();
System.Console.ReadLine();
}
}
Below is the App.config.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<connectionStrings>
<add name="MDISContext" connectionString="metadata=res://*/ModelEntities.csdl|res://*/ModelEntities.ssdl|res://*/ModelEntities.msl;provider=System.Data.SqlClient;provider connection string="data source=WIN-2012-SRVR-3;initial catalog=MDIS;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
If I just remove the entityFramework sections and database strings I get the following error:
{"Schema specified is not valid. Errors: \r\nModelEntities.ssdl(2,2) : error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information."}
Then if I remove the configuration section which does an entityframework registstration I get the same error.
All these errors go away if I add EntityFramework to the consoled project of my solution which also adds these entries into the app.config
The repository layer is going to look for the EF config in the configuration file loaded for the running app domain. So yes, your console app needs the configuration and that requires EF references. If your repositories were in an external service or another process then you would not need EF references.