问题
The deserialized class need to be store locally in sqlite database.
I am using xamarin forms PCL , the metadata need to save and retrieve locally in database.
I am not able to understand how can we save the deserialized C# class into database.
回答1:
As the comments have pointed out, using CreateTable will handle that for you. Taking from the Xamarin.Forms sample:
public TodoItemDatabase()
{
database = DependencyService.Get<ISQLite> ().GetConnection ();
// create the tables
database.CreateTable<TodoItem>();
}
Now you have the table to save to. You would call it like any other ORM:
public int SaveItem (TodoItem item)
{
lock (locker) {
if (item.ID != 0) {
database.Update(item);
return item.ID;
} else {
return database.Insert(item);
}
}
}
You don't have to worry about the specifics assuming you are using the Sqlite ORM wrapper: SQLite.Net-PCL nicely available from Nuget.
来源:https://stackoverflow.com/questions/26418449/i-have-deserialized-c-sharp-class-and-i-want-to-save-it-sqlite-using-xamarin-for