title: Xamarin.Android: SQLite-Net Extensions many-to-many - no such table, NULL collection
body: <p>I've installed SQLite-Net Extensions package into my Xamarin.Android project in Visual Studio 2015 and I'm trying to implement many-to-many relationship between <code>Person</code> and <code>Event</code> entities. I've followed <a href="https://bitbucket.org/twincoders/sqlite-net-extensions/" rel="nofollow noreferrer">the official documentation of the library</a>, but I can't make it working.</p>
  
  <p>Classes I created:</p>
  
  <p><strong>Person.cs:</strong></p>
  
  <pre><code>[Table("People")]
  public class Person
  {
      [PrimaryKey, AutoIncrement]
      public int Id { get; set; }
  
      public string Name { get; set; }
  
      public string LastName { get; set; }
  
      public string PhoneNumber { get; set; }
  
      public string Email { get; set; }
  
      [ManyToMany(typeof(PersonEvent), CascadeOperations = CascadeOperation.All)]
      public List&lt;Event&gt; Events { get; set; }
  }
  </code></pre>
  
  <p><strong>Event.cs:</strong></p>
  
  <pre><code>[Table("Events")]
  public class Event
  {
      [PrimaryKey, AutoIncrement]
      public int Id { get; set; }
  
      public string Name { get; set; }
      public DateTime Date { get; set; }
      public string Place { get; set; }
  
      [ManyToMany(typeof(PersonEvent), CascadeOperations = CascadeOperation.All)]
      public List&lt;Person&gt; Participants { get; set; }
  }
  </code></pre>
  
  <p><strong>PersonEvent.cs:</strong></p>
  
  <pre><code>public class PersonEvent
  {
      [ForeignKey(typeof(Person))]
      public int PersonId { get; set; }
  
      [ForeignKey(typeof(Event))]
      public int EventId { get; set; }
  }
  </code></pre>
  
  <p>To test it, I'm removing the database file to be sure a clean one is created on the device and then trying to create a <code>Person</code>, an <code>Event</code>, insert both into the DB first and then assign the <code>Event</code> to the <code>Person</code> and save again using <code>UpdateWithChildren</code> method:</p>
  
  <pre><code>var dbFile = new File(Constants.DbFilePath);
  dbFile.Delete();
  
  var db = new SQLiteConnection(new SQLitePlatformAndroid(), Constants.DbFilePath);
  db.CreateTable&lt;Person&gt;();
  db.CreateTable&lt;Event&gt;();
  db.CreateTable&lt;PersonEvent&gt;();
  
  var event1 = new Event
  {
      Name = "Volleyball",
      Date = new DateTime(2017, 06, 18),
      Place = "Sports hall"
  };
  
  var person1 = new Person
  {
      Name = "A",
      LastName = "B",
      PhoneNumber = "123456789"
  };
  
  
  db.Insert(person1);
  db.Insert(event1);
  person1.Events = new List&lt;Event&gt; { event1 };
  db.UpdateWithChildren(person1);
  </code></pre>
  
  <p>First of all, I needed to add <code>CreateTable&lt;PersonEvent&gt;()</code> line because if it wasn't present I was getting the exception: <code>SQLite.Net.SQLiteException: no such table: PersonEvent</code>, however I thought I don't have to create this intermediate table manually. Shouldn't SQLite-Net Extensions create it automatically somehow?</p>
  
  <p>With this line added, the first two inserts of <code>event1</code> and <code>person1</code> are working correctly (after inserting both entities have their Ids assigned). The <code>Events</code> collection on <code>person1</code> has even the <code>Event</code> created, which also has Id set:
  <a href="https://i.stack.imgur.com/aKIVm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aKIVm.png" alt="enter image description here"></a></p>
  
  <p>However, the "opposite entity", in this case <code>event1</code> has its <code>Participants</code> collection (List of <code>Person</code>) <code>NULL</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/H4fYV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H4fYV.png" alt="enter image description here"></a></p>
  
  <p>I tried everything and nothing is working. As I understood reading SQLite-Net Extensions docs, it should be resolved automatically. I even added this <code>CascadeOperations = CascadeOperation.All</code> on the collections, but it doesn't help as you can see. I'm I still doing something wrong?</p>