The Structure of the project :
有一个模块文件夹,我需要添加数据库并使存储库就在那里,其他模块和程序集可以使用它 . 新增内容:将其更改为先前已将配置文件放置在根应用程序中的状态,仍然存在错误 . 这篇文章完全编辑 .
The Database Location :
location:.... \ db \ db.sdf(卖出的app.config上面2级)
The App.Config file
location:modules \ ModuleX \(原名)
新地点:壳牌\(主体工程)
New Version :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<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=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="MyRecordzContext" connectionString="metadata=res://*...
</connectionStrings>
</configuration>
2 Cases of suspect : providerName = "System.Data.EntityClient"
LocalDbConnectionFactory
Error Info :
错误行:TblMyRecord MyRecord = context.MyRecords.First(w => w.MyRecord == stMyRecord);
错误:在应用程序配置文件中找不到名为'MyRecordzContext'的连接字符串 .
Goal :如何更改connectionstring,我的app.config使应用程序按预期工作
这里使用EF 5.0,SQL CE,Prism,WPF,MVVM,C#
Error :
错误:'System.Windows.Application'的类型初始值设定项引发了异常 .
在应用程序运行时出现 .
错误似乎在任何构建之前 .
Stack Trace :
PresentationFramework.dll!System.Windows.Application.Application()
Xz.Shell.exe!Xz.Shell.App.App()
Xz.Shell.exe!Xz.Shell.App.Main()
[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args)
Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state)
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart()
[Native to Managed Transition]
1 回答
这是我的预感:ModuleX是DAL项目,它是从我们称之为启动项目的另一个项目(可能是Web,Windows窗体或控制台应用程序)引用的 .
如果是这种情况,则不使用DAL项目中的App.Config文件 .
有两种解决方案:
您可以在启动项目中指定连接字符串,以便将其考虑在内 . 这意味着您需要在以下位置添加
<connectionStrings>...</connectionString>
标记:web.config,如果启动项目是Web应用程序
app.config,否则(例如WPF,控制台) .
或者,您可以在machine.config文件中定义此连接字符串,这将使其可用于在该特定计算机上运行的任何.NET应用程序 .
DAL项目中的连接字符串不在运行时使用 . 我认为它仅供EF设计师使用 .