不能将 SQLite 实体框架用作 DataGridView 数据源



我已经使用'实体数据模型向导'

从简单的SQLITE数据库中构建了一个实体框架模型

这很好,我已经编程了一段时间。

但是,我只是尝试将此SQLite实体框架模型用作DataGridView的数据源,并且无法将其视为数据源。一切都表明这应该是可能的。从同一数据库创建数据集,并且DataGridView可以将其用作数据源。

我更喜欢使用实体框架,但不明白为什么它没有将其视为有效的数据源。

请帮助!

按照此处的要求是app.config文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections></configSections>
  <system.data>
    <DbProviderFactories>
  <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>
  <system.diagnostics>
    <sources>
      <!-- This section defines the logging configuration for My.Application.Log -->
  <source name="DefaultSource" switchName="DefaultSwitch">
    <listeners>
      <add name="FileLog" />
      <!-- Uncomment the below section to write to the Application Event Log -->
      <!--<add name="EventLog"/>-->
    </listeners>
  </source>
</sources>
<switches>
  <add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
  <add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter" />
  <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
  <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
  </system.diagnostics>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
  </startup>
  <connectionStrings>
  <add name="simpleEntities" connectionString="metadata=res://*/GEM.Classes.test1.csdl|res://*/GEM.Classes.test1.ssdl|res://*/GEM.Classes.test1.msl;provider=System.Data.SQLite;provider connection string=&quot;data source=E:simple.db3&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

作为测试,我使用了一个非常简单的数据库:

CREATE TABLE SETTINGS (
KEY VARCHAR(50) PRIMARY KEY NOT NULL ,
VALUE VARCHAR(255)  NULL DEFAULT NULL);

决定抛弃EF,然后使用一个似乎效果很好的数据集。

最新更新