我已经反序列化了C#类,我想使用xamarin形式PCL将其保存为sqlite [英] I have deserialized C# class and i want to save it sqlite using xamarin forms PCL

查看:112
本文介绍了我已经反序列化了C#类,我想使用xamarin形式PCL将其保存为sqlite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

反序列化的类需要本地存储在sqlite数据库中.

The deserialized class need to be store locally in sqlite database.

我正在使用xamarin形式PCL,元数据需要在数据库中本地保存和检索.

I am using xamarin forms PCL , the metadata need to save and retrieve locally in database.

我不明白如何将反序列化的C#类保存到数据库中.

I am not able to understand how can we save the deserialized C# class into database.

推荐答案

正如注释所指出的那样,使用CreateTable将为您处理该问题.从Xamarin.Forms示例中获取:

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>();
}

现在您具有要保存到的表.您会像其他任何ORM一样称呼它:

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);
        }
    }
}

假设您正在使用Sqlite ORM包装器,则不必担心具体细节:Nuget很好地提供了SQLite.Net-PCL.

You don't have to worry about the specifics assuming you are using the Sqlite ORM wrapper: SQLite.Net-PCL nicely available from Nuget.

这篇关于我已经反序列化了C#类,我想使用xamarin形式PCL将其保存为sqlite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆