'没有连接字符串名为' iicmdataentities'可以在应用程序配置文件中找到。' EF6-修订加载项

发布于 01-24 21:21 字数 145 浏览 2 评论 0原文

AM构建文件.dll revit Addin具有实体框架6,而我的错误输入图像说明在这里帮我

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昔梦2025-01-31 21:21:19

首先,您需要让命令知道app.config在哪里。由于某种原因,我们有Revitapi的问题。
好,但是...我们怎么做?
首先,您需要将引用添加到system.configuration.dll
如果您右键单击“参考” 在您的解决方案资源管理器中,然后在“ assemblies” tab下单击,搜索配置:

i.sstatic.net/to9ag.png“ rel =“ nofollow noreferrer” > ,您需要创建配置对象,给出Addin Dll的确切位置。
以下代码确实确切地说:

 Configuration config = ConfigurationManager.OpenExeConfiguration
                (System.Reflection.Assembly.GetExecutingAssembly().Location);
 var connString = config.ConnectionStrings.ConnectionStrings["DevelopmentConnection"].ConnectionString;

使用连接字符串值,您可以将其传递给dbContext内部的execute> rececute方法:

    [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!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文