【问题标题】:How to make Entity Framework CTP5 work with SQLite?如何使实体框架 CTP5 与 SQLite 一起工作?
【发布时间】:2011-02-04 17:47:53
【问题描述】:

我很难将 SQLite db 与 EF CTP5 一起使用。我只是想用 SQLite 执行这个MSDN example。但就在这条线上

var food = db.Categories.Find("FOOD");

我遇到了运行时异常:

System.Data.SQLite.SQLiteException (0x80004005): SQLite errorno such table: Categories

注意:需要修改app.config文件,内容如下:

App.config

<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" />
  </startup>
  <runtime>
    <generatePublisherEvidence enabled="false" />
  </runtime>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite"/>
      <add name="SQLite Data Provider" invariant="System.Data.SQLite"
           description=".Net Framework Data Provider for SQLite"
           type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="ProductContext" connectionString="Data Source=D:\CodeFirst.db;Version=3;New=True;" providerName="System.Data.SQLite" />
  </connectionStrings>
</configuration>

【问题讨论】:

标签: c# .net-4.0 entity-framework-4 sqlite ef-code-first


【解决方案1】:

在我看来,当前的 SQLite.net 首先不支持实体框架 CTP5 代码。将不得不等待它发生。

【讨论】:

    【解决方案2】:

    System.Data.SQLite 目前不提供 CreateDatabase() 和 DeleteDataase() 动态数据库创建。至少,this forum post 大约一个月没有得到答复。
    我们已经提供动态数据库创建和 CTP 5 支持,并计划很快在 dotConnect for SQLite 上发布有关 CTP 5 支持的博客。
    更新CTP 5 article 可用。它包含一些关于数据库创建特性的注释,以及一个说明 CTP 5 用法的示例。

    【讨论】:

    • Devart - 急切地等待着博文。我找不到关于 dotconnect for sqlite 的信息,代码首先是 ctp5。没有任何!我什至在 Devart 论坛上发帖,并从 Devart 网站发送了一封电子邮件。
    • @user327325,我们已经发布了这篇文章。查看答案的更新。
    【解决方案3】:

    【讨论】:

    • 虽然这在理论上可以回答问题,it would be preferable 在此处包含答案的基本部分,并提供链接以供参考。
    【解决方案4】:

    添加

    Database.SetInitializer<MyDataContext>(null);
    

    为我工作。我首先使用EF5 代码和Sqlite

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-30
      • 2014-09-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多