0

am build file .dll Revit Add-in has Entity Framework 6 and my errors enter image description here Help me

Blue1412
  • 11
  • 1

1 Answers1

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:

enter image description here

Then, you need to create a Configurationobject, 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!