AnsweredAssumed Answered

C# Addin with Entity Framework 6 (EF6)

Question asked by Michael Corriveau-Cote on Aug 16, 2018
Latest reply on Aug 16, 2018 by Andrew Johnson

Hey everyone,

 

First timer here! I would normally post my questions on Stack Overflow but I believe that this place might be more optimal when it comes to questions about Solidworks and building a C# addin.

 

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.

 

Adding ADO.Net Entity Data Model to project - Step 1 - Imgur.png

Adding ADO.Net Entity Data Model to project - Step 2 - Imgur.png

Adding ADO.Net Entity Data Model to project - Step 3 - Imgur.png

Adding ADO.Net Entity Data Model to project - Step 4 - Imgur.png

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 = "myemail@mycompany.com",
                DateProduite = DateTime.Now
            };
            context.WillyDemandes.Add(newDemande);
            context.SaveChanges();

 

NOTE : I'd also like to know how to properly add a code snippet. (Answered)

 

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.'

 

Solidworks Addin - EF6 Error - No connection string named 'Entities' could be found in the application config file - Imgur.png

 

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.

 

The content is in my config file :

 

Solidworks Addin - EF6 Error - Config File - Imgur.png

 

Ce message a été modifié par : Michael Corriveau-Cote (Adding pictures)

 

Ce message a été modifié par : Michael Corriveau-Cote (How to add code Snippet?)

Outcomes