1

I'm trying to save my objects that I got back from my JSON into a local storage db with SQLite

I've imported a lot of packages and also the SQLite framework.

I've also made these two classes: 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 members

   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
}

An activty can have more ActivityMembers. When I build and run I get the following error: enter image description here

When I debug I found out that it is caused by the following lines: In Activity:

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

In activityMember:

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

Any help on how correctly doing this?

EDIT I've these references:

enter image description here

Steaphann
  • 2,797
  • 6
  • 50
  • 109
  • 1
    Not sure if this is the same problem, but it looks like it could be: http://stackoverflow.com/questions/23463849/sqlite-extension-is-not-working-as-expected – Sebastian L May 27 '15 at 07:56
  • @SebastianL yes, it's the same error in the same platform, and it seems to be caused by the same issue. – redent84 May 27 '15 at 09:30

1 Answers1

0

The error is being caused by SQLite.Net trying to serialize the property with type List<ActivityMember>, that it's a type that SQLite.Net doesn't know about. By annotating it with the SQLite-Net Extensions OneToMany attribute, it should be ignored by SQLite.Net, because OneToMany inherits from SQLite.Net Ignore attribute.

If the property is not being ignored by SQLite.Net is because the Ignore attribute is not being recognized. This issue is usually caused because you are using a different SQLite.Net version that the version against SQLite-Net Extensions was compiled. To fix this issue, you have to make sure that the versions of SQLite.Net used are the same.

To solve it you can copy the SQLite-Net Extension sources to your project to force the library to link against your version of SQLite-Net.

Response to EDIT:

As you can see in your references, you have two SQLite.Net libraries:

  • SQLite.Net (and its asynchronous API SQLite.Net.Async)
  • SQLite for Windows Phone

You have to remove the references to SQLiteNetExtensions, SQLite.Net.Async and SQLite.Net.Async, and compile SQLite-Net Extensions sources against your SQLite For Windows Phone library.

redent84
  • 18,901
  • 4
  • 62
  • 85
  • Were can I get those sources? And I just copy paste it in my solution? Sorry very new to windows dev.. – Steaphann May 27 '15 at 11:31
  • Maybe a stupid question. But what do you mean with compile SQLite-net Extensions sources against... – Steaphann May 27 '15 at 13:00
  • I mean recompile SQLite-Net Extensions from the sources using the same SQLite.Net dependency that you are using in your project. The simplest approach is just copy the sources to your project, this way you are forcing the library to use the same dependency that you are using. – redent84 May 27 '15 at 15:03
  • So I just download it from sources and then add an existing project to my solution? And do I need to add SQLiteNetExtensions-MvvmCross.csproj or SQLiteNetExtensions-PCL.csproj? – Steaphann May 28 '15 at 14:26
  • Just copy the content of the `Attributes`, `Extensions` and `Exceptions` folders to your project. – redent84 May 28 '15 at 16:06