如何使用C#将自定义对象保存到Windows Phone上的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; }
public List<Address> Items { get; set; }
}
public class Address
{
public string city { get; set; }
public string state { get; set; }
public string pin { get; set; }
}
如何将Person插入sqlite数据库以及如何阅读?
最佳答案
这是我的代码示例:
private const string db_name = "store4.sqlite";
SQLiteAsyncConnection connection = new SQLiteAsyncConnection(db_name);
public async void InsertInspections(ObservableCollection<Inspections> inspections)
{
connection.CreateTableAsync<Inspections>().Wait();
foreach (var inspection in inspections)
{
var task = connection.Table<Inspections>().
Where(v => v.InspectionId == inspection.InspectionId).ToListAsync();
task.Wait();
if (task.Result.Any())
connection.UpdateAsync(inspection);
else
connection.InsertAsync(inspection);
}
}
关于c# - 如何使用C#将自定义对象保存到Windows Phone上的sqlite中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26713046/