How to make Entity Framework CTP5 work with SQLite?

十年热恋 提交于 2019-12-10 14:28:34

问题


I am having a very hard time in using the SQLite db with EF CTP5. I was just trying to execute this MSDN example with SQLite. But at the line

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

I am getting a runtime exception:

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

Note: The app.config file has to be modified and is as follows:

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>

回答1:


It seems to me that current SQLite.net does not support Entity Framework CTP5 code first. Will have to wait for that to happen.




回答2:


System.Data.SQLite does not provide CreateDatabase() and DeleteDataase() dynamic database creation at the moment. At least, this forum post is unanswered for approximately a month.
We already offer both dynamic database creation and CTP 5 support, and plan to blog about CTP 5 support in dotConnect for SQLite soon.
UPDATE. The CTP 5 article is available. It contains some notes concerning database creation peculiarities, and a sample illustrating CTP 5 usage.




回答3:


you can see this:

http://www.devart.com/blogs/dotconnect/index.php/entity-framework-code-first-support-for-oracle-mysql-postgresql-and-sqlite.html




回答4:


Adding

Database.SetInitializer<MyDataContext>(null);

works for me. I use EF5 code first with Sqlite



来源:https://stackoverflow.com/questions/4901198/how-to-make-entity-framework-ctp5-work-with-sqlite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!