【问题标题】:Code sample using DBLinq, SQLite使用 DBLinq、SQLite 的代码示例
【发布时间】:2011-06-20 19:29:24
【问题描述】:

有人可以发布一个使用 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 文件吗?

【问题讨论】:

  • 能否请您出示您已有的代码,以便我们为您提供帮助。

标签: sqlite dblinq


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-16
    • 2016-01-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多