am build file .dll Revit Add-in has Entity Framework 6 and my errors enter image description here Help me
Asked
Active
Viewed 63 times
1 Answers
0
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!

Leandro Manes
- 33
- 7