I have deserialized C# class and i want to save it sqlite using xamarin forms PCL

时光总嘲笑我的痴心妄想 提交于 2019-12-13 20:53:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!