1

我正在尝试让 sqlite 与 linq 一起工作。到目前为止,我已经:

从http://sourceforge.net/projects/sqlite-dotnet2/files/SQLite%20for%20ADO.NET%202.0/安装了 ADO.net 提供程序

从http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki安装了 32 位和 64 位 sqlite .net

现在我可以使用 sqlite 数据库作为源创建实体数据模型。每当我尝试创建数据模型的新实例(在显示的 wpf 组件中)时,都会出现以下异常:

A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in     PresentationFramework.dll

Additional information: 'The invocation of the constructor on type myprogram.mycomponent' that matches the specified binding constraints threw an exception.' Line number '13' and line position '37'.

mycomponent 构造函数很简单:

private void myprogram()
{
    InitializeComponent();

    pricesEntities pe = new pricesEntities();
}

当我打开显示组件的窗口的设计视图时,我得到一个

ArgumentException was thrown on "mycomponent": Cannot create an instance of "mycomponent".

An Unhandled Exception has occurred

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
  at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
  at System.Data.EntityClient.EntityConnection..ctor(String connectionString)
  at System.Data.Objects.ObjectContext.CreateEntityConnection(String connectionString)
  at System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName)
  at myprogram.pricesEntities..ctor() in <path>\prices.Designer.cs:line 34
  at myprogram.ItemList.InitializePriceList() in <path>\ItemList.xaml.cs:line 34
  at myprogram.ItemList..ctor() in <path>\ItemList.xaml.cs:line 29

我的 app.config 包含以下连接字符串:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="pricesEntities" connectionString="metadata=res://*/prices.csdl|res://*/prices.ssdl|res://*/prices.msl;provider=System.Data.SQLite;provider connection string='data source=&quot;<path>\prices.db&quot;'" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

我尝试按照此处和其他地方的建议将 app.config 文件复制到可执行文件的目录中。那没有帮助。请注意,这与配置中未找到指定的命名连接、不打算与 EntityClient 提供程序一起使用或无效的问题不同

我只有一个项目(一个 wpf 应用程序)要开始工作。

4

1 回答 1

1

发现这是因为它是 2.x 运行时的程序集构建,所以我将useLegacyV2RuntimeActivationPolicy元素添加到我的 app.config 并解决了问题。

于 2012-08-28T18:01:21.960 回答