如何在Windows 8中将sqlite表和列映射到c#类

Tem*_*iwa 4 sqlite windows-8

我在C#中为Windows 8构建了我的第一个应用程序(我是一个完整的菜鸟).我有一些我创建的类.当应用程序运行时,它需要从sqlite数据库中读取数据.我为每个表都有一个类,但我不知道如何将每个类属性映射到数据库中的相应列.我似乎无法找到任何信息,我看到的所有东西似乎都是自动映射它们,或者没有提到它是如何完成的,例如

public class Person
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }

[MaxLength(30)]
public string Name { get; set; }

[MaxLength(30)]
public string Surname { get; set; }

}
Run Code Online (Sandbox Code Playgroud)

样品

var query = conn.Table<Person>().Where(x => x.Name == "Matteo");
var result = await query.ToListAsync();
foreach (var item in result)
{
    Debug.WriteLine(string.Format("{0}: {1} {2}", item.Id, item.Name, item.Surname));
}
Run Code Online (Sandbox Code Playgroud)

有什么我缺少的东西或某种教程吗?我以前从未使用过sqlite.

Tem*_*iwa 9

好吧,我觉得很愚蠢......事实证明你必须在课堂上设置表格和列属性.例如

[Table("sometable")]
class Element
{
    [Column(Name = "id")]
    public int Id { get; set; }

    [Column("columnone")]
    public string PropertyOne {get; set;}

    [Column("columntwo")]
    public string PropertyTwo {get; set;}
}
Run Code Online (Sandbox Code Playgroud)