创建sqlite .net实体数据模型时抛出异常

时间:2012-08-28 16:42:47

标签: linq sqlite system.data.sqlite

我正在尝试让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文件复制到可执行文件的目录中,如此处和其他地方所建议的那样。这没有用。请注意,这与The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid

不同

我只有一个项目(一个wpf应用程序),我正在努力工作。

1 个答案:

答案 0 :(得分:1)

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