是否有人能够使用DBLinq,SQLite发布具有有效连接的小代码示例?我一直在努力让自己在VS 2010 WPF环境中运行2天。我想我已经解决了连接字符串,但是很想看到样本正常运行。
var con = new SQLiteConnection("DbLinqProvider=Sqlite;Version=3;Data Source=c:\\temp\\testdb.db3;");
DataSource db = new DataSource(con);
var q = from c in db.Person
select c;
foreach (Person tempPerson1 in q)
MessageBox.Show(tempPerson1.Name);
我的DBML文件(相关代码) - 我将“Main”更改为“DataSource”,将SQLite更改为System.Data.SQLite.SQLiteConnection以进行编译。
[global::System.Data.Linq.Mapping.DatabaseAttribute(Name="DataSource")]
[global::System.Data.Linq.Mapping.ProviderAttribute(typeof(System.Data.SQLite.SQLiteConnection))]
public DbLinq.Data.Linq.Table<Person> Person {
get {
return this.GetTable<Person>();
}
}
[global::System.Data.Linq.Mapping.TableAttribute(Name="Datasource.Person")]
public partial class Person {
private string _id;
private string _name;
public Person() { }
[global::System.Data.Linq.Mapping.ColumnAttribute(
Name="id", Storage="_id", DbType="VARCHAR(10)")]
public string ID {
get {
return this._id;
}
set {
if ((this._id != value)) {
this._id = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(
Name="name", Storage="_name", DbType="VARCHAR(25)")]
public string Name {
get {
return this._name;
}
set {
if ((this._name != value)) {
this._name = value;
}
}
}
}
我目前收到的SQLite错误是没有这样的表:Datasource.Person和我相信我有路径并且连接字符串正确。我应该从DBMetal生成DBML文件和CS文件吗?
答案 0 :(得分:3)
解决方案:我重新生成了DBML文件,没有将“main”更改为其他名称,包括对“Using System.Data.SQLite”的引用并更改了
[global::System.Data.Linq.Mapping.ProviderAttribute(typeof(Sqlite))]
到
[global::System.Data.Linq.Mapping.ProviderAttribute(typeof(SQLiteConnection))]
现在似乎正在工作,我终于从我的数据库中获得了结果。