Windows phone 具有 sqlite 本地存储的应用程序

Windows phone app with sqlite local storage

我正在尝试使用 SQLite

将我从 JSON 取回的对象保存到 local storage 数据库中

我已经导入了很多包和 SQLite 框架。

我也做了这两个类: Activity

public class Activity : INotifyPropertyChanged
    {
        [SQLite.PrimaryKey, SQLite.AutoIncrement]
        public int act_id
        {
            get;
            set;
        }
        //The Id property is marked as the Primary Key
        private int act_organization_id_value;
        private int act_creator_id_value;
        private int act_free_value;
        private int act_subcription_value;
        private int act_external_value;
        private int act_active_value;
        private int act_future_value;
        private int act_status_value;
        private int act_viewed_value;
        private string act_location_value = String.Empty;
        private string act_lng_value = String.Empty;
        private string act_title_value = String.Empty;
        private string act_information_value = String.Empty;
        private string act_type_value = String.Empty;
        private string act_color_value = String.Empty;
        private string act_event_identifier_value = String.Empty;
        private DateTime act_start_value = DateTime.Now;
        private DateTime act_end_value = DateTime.Now;

         [OneToMany(CascadeOperations = CascadeOperation.All)]
        public List<ActivityMember> membrs { get; set; }

       //Other getters and setters
}

Activity 成员

   public class ActivityMember : INotifyPropertyChanged
    {
        [SQLite.PrimaryKey, SQLite.AutoIncrement]
        public int mem_id
        {
            get;
            set;
        }

        private int mem_activity_id_value;
        private int mem_organization_id_value;
        private int mem_role_id_value;
        private int mem_creator_value;
        private int mem_accepted_value;
        private int mem_activity_accepted_value;
        private int mem_active_value;
        private int mem_deleted_value;
        private string mem_profile_color_value = String.Empty;
        private string mem_picture_value = String.Empty;
        private string mem_email_value = String.Empty;
        private string mem_phone_value = String.Empty;
        private string mem_gsm_value = String.Empty;
        private string mem_address_value = String.Empty;
        private string mem_postal_value = String.Empty;
        private string mem_city_value = String.Empty;
        private string mem_country_id_value = String.Empty;
        private string mem_first_name_value = String.Empty;
        private string mem_last_name_value = String.Empty;
        private string mem_extra_info_value = String.Empty;
        private string mem_street_value = String.Empty;
        private string mem_streetnumber_value = String.Empty;
        private string mem_gender_value = String.Empty;
        private DateTime mem_birthdate_value = DateTime.Now;

        [ManyToOne]      // Many to one relationship with Activity
        public Activity activity { get; set; }

        // all other getters and setters
}

一个活动可以有更多 Activity 成员。 当我构建 运行 时,出现以下错误:

调试的时候发现是以下几行引起的: 在 Activity:

   [OneToMany(CascadeOperations = CascadeOperation.All)]
        public List<ActivityMember> membrs { get; set; }

活动成员:

  [ManyToOne]      // Many to one relationship with Activity
    public Activity activity { get; set; }

任何有关如何正确执行此操作的帮助?

编辑 我有这些参考资料:

错误是由 SQLite.Net 试图用类型 List<ActivityMember> 序列化 属性 引起的,SQLite.Net 不知道它是什么类型。通过使用 SQLite-Net Extensions OneToMany 属性注释它,它应该被 SQLite.Net 忽略,因为 OneToMany 继承自 SQLite.Net Ignore 属性。

如果 属性 没有被 SQLite.Net 忽略是因为 Ignore 属性没有被识别。此问题通常是因为您使用的是针对 SQLite-Net Extensions 的版本编译的不同 SQLite.Net 版本。要解决此问题,您必须确保使用的 SQLite.Net 版本相同。

要解决这个问题,您可以将 SQLite-Net Extension sources 复制到您的项目中,以针对您的 SQLite-Net 版本强制库 link。

对编辑的回应

如您在参考文献中所见,您有两个 SQLite.Net 库:

  • SQLite.Net(及其异步 API SQLite.Net.Async)
  • 用于 Windows Phone
  • 的 SQLite

您必须删除对 SQLiteNetExtensionsSQLite.Net.AsyncSQLite.Net.Async 的引用,并针对您的 SQLite For Windows Phone 库编译 SQLite-Net Extensions sources