I'm working right now on upgrading a VB.net Solidworks addin to a better version of it but in CSharp. I'm trying to migrate towards Entity Framework 6 when it comes to Database integration.
So I started a Visual Studio 2017 SwAddin C# project. You can follow my steps in this post here. I then added the NuGet Package Entity Framework.
When this is done, i'm adding an ADO.net Entity Data Model to my project.
Then you may use a syntax like this one to Insert a new entry :
Info_IndusEntities context = new Info_IndusEntities();
WillyDemandes newDemande = new WillyDemandes()
{
PathModel = "ModelTest",
ConfigName = "ConfigTest",
Revision = 1,
Priority = 2,
Statut = "EnTest",
WilmaTQ = true,
WilmaRBRE = true,
WilmaRBTK = true,
WilmaTLS = true,
GenerateBOM = true,
PdfPage = "L;",
ECO = "ECO #1234",
SendingComputer = System.Environment.MachineName,
Username = System.Environment.UserName,
MailAddress = "[email protected]",
DateProduite = DateTime.Now
};
context.WillyDemandes.Add(newDemande);
context.SaveChanges();
The problem is that this would work fine in any other projet. I tried a C# console project for example. But when it comes to trying this in an Addin, i'm getting the following error :
'No connection string named 'Entities' could be found in the application config file.'
I tried many things like changing the App.config "Build Action" to Embedded Ressource, or changing the "Copy to Output Directory" property to Always Copy but nothing seems to work.
This is a Class Librabry project and this is the Startup project of the solution.
The content is in my config file :
Unfortunately the way Solidworks is loading your addin dll prevents you (or libraries that you are using like EF) from accessing .config file in the usual way. The easiest solution for you is to use overloaded constructor for your entities object and pass connection string from code.