sqlite - 使用 DBLinq、SQLite 的代码示例

标签 sqlite dblinq

有人可以发布一个使用 DBLinq、SQLite 进行工作连接的小代码示例吗?我已经在 VS 2010 WPF 环境中努力让它启动并运行两天了。我想我已经解决了连接字符串,但很想看到示例的启动和运行。

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 文件吗?

最佳答案

解决方案:我重新生成了 DBML 文件,没有将“main”更改为其他名称,包括对“Using System.Data.SQLite”的引用并进行了更改

[global::System.Data.Linq.Mapping.ProviderAttribute(typeof(Sqlite))]

[global::System.Data.Linq.Mapping.ProviderAttribute(typeof(SQLiteConnection))]

似乎现在正在工作,我终于从我的数据库中得到了结果。

关于sqlite - 使用 DBLinq、SQLite 的代码示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6416373/

相关文章:

android - 如何从数据库文件生成 SQLite 实体关系图

mysql - 在sqlite中选择频率计数的列名

MySQL 时间戳到 .NET 时间戳

c# - DBMetal 为 sqlite_sequence 生成无效类

database - DbMetal 对 SQLite 中重复的外键引用感到窒息——有什么想法吗?

php - 无法通过 php 5.3.0 写入 SQlite3 上的 chmod 777 数据库文件

java - sqlite 中的列类型 NONE

webpack - 带有 sqlite3 和 webpack 的 Electron 打包器

c# - 通过 DbLinq 使用 Linq to SQLite 创建记录

c# - .NET/C# Drizzle 数据库客户端