SQLite与EF Code First

nic*_*ick 10 sqlite entity entity-framework code-first

在使用SQLite和NHibernate成功之后,我很高兴使用它来进行Entity Framework Code First测试.

如果您有一些示例连接字符串并设置演示,这将是很好的,并节省一点时间从忙碌的一天.

非常感谢.

编辑:

值得一提的是,在通过EF"数据上下文"应用crud操作时,我在调试期间收到此错误:

无法确定"System.Data.SQLite.SQLiteConnection"类型连接的提供程序名称.

<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" />
    </DbProviderFactories>
</system.data>


<connectionStrings>
    <add name="DataContext"
         connectionString="Data Source=:memory:;Version=3;New=True;"
         providerName="System.Data.SQLite"
     />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)

希望EF能够以这种方式与SQLite集成.虽然错误消息令人担忧,但可能并非如此.

Max*_*oro 6

您需要使用程序集限定名称:

<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" />
Run Code Online (Sandbox Code Playgroud)


Dam*_*enG 5

Code First应该适用于任何ADO.NET 3.5级别的提供程序(这些实现实体框架功能).

支持4.0的提供程序还添加了DeleteDatabase/CreateDatabase/DatabaseExists功能.

Code First除此之外不需要额外的提供程序功能.

会发生什么,它会查看Connection的类型,然后尝试将其映射回提供程序及其提供程序工厂,以便它可以创建所需的所有其他内容.

值得检查以确保在GAC中安装了支持3.5级功能的最新SQLLite提供程序.