![](/img/trans.png)
[英]how to save custom object into sqlite database on windows phone8 using c#?
[英]How to save custom object into sqlite on windows phone using c#?
如何使用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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.