【发布时间】:2014-03-16 07:32:24
【问题描述】:
我创建了一个属性类来表示我的 SQLite 数据库的表模式。类中的每个属性都成为数据库中的一个属性。
class SQLiteTables
{
public class tblPerson
{
[PrimaryKey, AutoIncrement]
public int PersonID { get; set; }
public string PersonFirstName { get; set; }
public string PersonMiddleName { get; set; }
public string PersonLastName { get; set; }
}
public class tblSchedule
{
[PrimaryKey, AutoIncrement]
public int ScheduleID { get; set; }
public string ScheduleDescription { get; set; }
public DateTime ScheduleStart { get; set; }
public DateTime ScheduleEnd { get; set; }
}
//18 more table definitions below
}
现在,要从表中检索一些数据,
public void GetPersonList()
{
List<tblPerson> lstTemp = dbConn.Table<tblPerson>().ToList<tblPerson>();
// Some 20 lines of code here
}
我想避免编写特定于类型的方法,这是一项乏味的任务。我想创建一个可重用的方法,它可以使用泛型实现检索任何表上的数据。我怎样才能做到这一点?
编辑我正在使用 Windows Phone 8 平台。
【问题讨论】:
-
一种方法是使用 ORM,例如实体框架。
标签: c# sqlite generics windows-phone-8 type-constraints