Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using entity model in class library

I have a project solution consisting of two class libraries and a Windows Application. The two libraries are split into Custom_Classes and Custom_Controls.

Im my Custom_Classes library I have a entity model that is referenced from my Custom_Controls library to access certain data members. The connections work fine and when I add a control to my windows form it does not have any problems. But when I want to add a custom control inside another one dragging it from the toolbox the following message appears.

Failed to create component 'u_Settings'. The error message follows: ' No connection string named 'MyEntitiesCon' could not be found in the application config file.'

I have made sure that the connection string is in the app.config file and even tried adding it in the project settings file. Here is my connection string copied from the Custom_Classes project to the Custom_Controls project

<connectionStrings>
    <add name="MyEntitiesCon" connectionString="metadata=res://*/Enity_Framework.SP_Model.csdl|res://*/Enity_Framework.SP_Model.ssdl|res://*/Enity_Framework.SP_Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=XXX\XXX;initial catalog=XXX;integrated security=True;connect timeout=30;connectretrycount=2;MultipleActiveResultSets=True;App=EntityFramework&quot;"      providerName="System.Data.EntityClient" />
</connectionStrings>

I have tried a bunch of solutions but with no success

  • Problem using ADO.NET Entity Framework from a DLL class-library
  • How to: Use a Model Defined in a Class Library (Entity Data Model Tools)
like image 948
Juan Gous Avatar asked May 13 '26 10:05

Juan Gous


1 Answers

Firstly this seems like a bad design, braking SOLID principles. You should depend on abstract DataSource interface. The datasource implementation should be separated from the control.

There's nice guideline at MSDN too:

http://msdn.microsoft.com/en-us/library/ms171926.aspx

PS. Open the EF designer and try to update the model. Save the connection string and copy it to the project where you design your controls.

like image 178
Andrew Avatar answered May 16 '26 01:05

Andrew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!