I have created a class library project, which contains the entity framework object, who will be responsible for common data access layer for my multiple project. After adding the generated dll file to my domain project, and using the entity object from the class library project, I am facing with the following issue.
No connection string named 'ABC' could be found in the application config file.
I have set the Metadata Artifact processing property of edmx to Embed in Output Assembly.
App.Config markup
<?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=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="ABC" connectionString="metadata=res://*/Entity.ABC.csdl|res://*/Entity.ABC.ssdl|res://*/Entity.ABC.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\ABC.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>
And Entities code are as follow
public ABC_IntegrationEntities()
: base("name=ABC")
{
}
One more thing: I am accessing database from datadirectiory "App_Data".
I am referencing the blog from dotnetcurry.com.
Install Entity Framework to your Project. Right click on your project name and select Manage NuGet Packages. Go to Browse and Select Entity Framework then click Install button to install Entity Framework on your project.
edmx . Go to solution Explorer > select Satyadatabasemodel.Context.tt under Satyadatabasemodel. edmx > Right click and Go to Properties > Enter "Custom Tool Namespace" value. Our class library project name is "Entities" > Save.
Based on the link you gave, probably you miss this part.
Now you can either create your own .config file in this project and add the connectionstring entry of your model or simply copy the App.config file that you created in the MyEntityModel project, in your Console App project. We will adopt the simpler way. Right click the project > Add Existing Item > Go to the MyEntityModel project and add the App.config file.
Explanation:
When you create a library and the library is referenced from another project, EF will read the config that is relative to start up project. You can do one of the following.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With