有没有人可以发布一个小的代码示例,它使用DBLinq,SQLite建立了一个工作连接?我已经在VS2010WPF环境中挣扎了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文件?
发布于 2011-06-21 20:48:07
解决方案:我重新生成了DBML文件,没有将"main“更改为不同的名称,而是包含了对”使用System.Data.SQLite“的引用,并更改了
[global::System.Data.Linq.Mapping.ProviderAttribute(typeof(Sqlite))]至
[global::System.Data.Linq.Mapping.ProviderAttribute(typeof(SQLiteConnection))]现在似乎工作了,我终于从我的数据库中得到了结果。
https://stackoverflow.com/questions/6416373
复制相似问题