![](/img/trans.png)
[英]WCF with EF6 - No connection string named 'Entities' could be found in the application config file , [I SET IT]
[英]C# addin with EF6 - No connection string named 'Entities' could be found in the application config file
我現在正在將VB.net Solidworks插件升級到更好的版本,但使用的是CSharp。 在數據庫集成方面,我正在嘗試向Entity Framework 6遷移。
所以我開始了Visual Studio 2017 SwAddin C#項目。 您可以在此處按照我的步驟進行操作。 然后,我添加了NuGet包實體框架。
完成此操作后,我將ADO.net實體數據模型添加到我的項目中。
然后,您可以使用像這樣的語法來插入新條目:
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();
問題是,這在任何其他項目中都可以正常工作。 例如,我嘗試了一個C#控制台項目。 但是,在Addin中嘗試此操作時,出現以下錯誤:
'在應用程序配置文件中找不到名為'Entities'的連接字符串。
我嘗試了許多操作,例如將App.config“構建操作”更改為Embedded Ressource,或將“復制到輸出目錄”屬性更改為“始終復制”,但似乎無濟於事。
這是Class Librabry項目,這是解決方案的Startup項目。
內容在我的配置文件中:
不幸的是,Solidworks加載您的插件dll的方式阻止了您(或您正在使用的庫,如EF)以通常的方式訪問.config文件。 對您來說,最簡單的解決方案是對實體對象使用重載的構造函數,並從代碼中傳遞連接字符串。
為了解決這個問題
1- 將項目設置為啟動項目
2- 確保在entityFramework部分之后添加連接字符串:
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<connectionStrings>
<!-- your connection string goes here, after configSection -->
</connectionString>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.