首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用DBLinq和SQLite的代码示例

使用DBLinq和SQLite的代码示例
EN

Stack Overflow用户
提问于 2011-06-21 03:29:24
回答 1查看 4K关注 0票数 2

有没有人可以发布一个小的代码示例,它使用DBLinq,SQLite建立了一个工作连接?我已经在VS2010WPF环境中挣扎了2天了。我想我已经弄好了连接字符串,但我希望看到一个样例启动并运行。

代码语言:javascript
复制
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以进行编译。

代码语言:javascript
复制
[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文件?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-21 20:48:07

解决方案:我重新生成了DBML文件,没有将"main“更改为不同的名称,而是包含了对”使用System.Data.SQLite“的引用,并更改了

代码语言:javascript
复制
[global::System.Data.Linq.Mapping.ProviderAttribute(typeof(Sqlite))]

代码语言:javascript
复制
[global::System.Data.Linq.Mapping.ProviderAttribute(typeof(SQLiteConnection))]

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6416373

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档