【发布时间】:2012-10-10 02:44:31
【问题描述】:
我使用“实体数据模型向导”从一个简单的 SQLite 数据库构建了一个实体框架模型
这很好用,我已经编写了一段时间了。
但是,我刚刚尝试将此 SQLite 实体框架模型用作 DataGridView 的数据源,但它无法将其视为数据源。一切都表明这应该是可能的。从同一数据库创建 DataSet 是可行的,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="data source=E:\simple.db3"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
作为测试,我使用了一个非常简单的数据库:
CREATE TABLE SETTINGS (
KEY VARCHAR(50) PRIMARY KEY NOT NULL ,
VALUE VARCHAR(255) NULL DEFAULT NULL);
【问题讨论】:
-
会不会是你的web.config文件中没有添加相应的条目?
-
请显示相关的代码。 DGV 可以接受 DbSet(或 ObjectSet)作为数据源,因此肯定有其他问题。
-
我已按要求添加了 app.config 文件和 sql。
-
Gert - 我正在尝试使用 UI 设计器中的属性对话框设置数据源。如果在此处设置,我可以更轻松地配置 DGV。
标签: vb.net entity-framework sqlite datasource