''No connection string named 'IICMDATAEntities' could be found in the application config file.' EF6 - Revit Add-in
am build file .dll Revit Add-in has Entity Framework 6 and my errors enter image description here Help me
Solution 1:[1]
Firstly, you need to let your command know where your app.config
is. For some reason, we have this issue with RevitAPI.
Ok, but... How we do that?
To begin with, you need to add a reference to System.Configuration.dll
.
It's easily found if you right click "References" in your solution explorer, and then under "Assemblies" tab, search for configuration:
Then, you need to create a Configuration
object, giving the exact location of your addin dll.
The following piece of code does exact that:
Configuration config = ConfigurationManager.OpenExeConfiguration
(System.Reflection.Assembly.GetExecutingAssembly().Location);
var connString = config.ConnectionStrings.ConnectionStrings["DevelopmentConnection"].ConnectionString;
With the connection string value in hand, you can simply pass it to the constructor of your DbContext
inside your Execute
method:
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class MyRevitAPICommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
MyContext myContext = new MyContext(connString);
//if using mvvm, can pass this context around to achieve what you desire.
}
}
Done!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Leandro Manes |