title: How can a foreign key be mapped onto an object field in SQLite-Net Extensions?
body: <p><strong>Context:</strong>
  We are using <code>SQLite-Net Extensions</code> for local data caching with <code>Xamarin</code>. We plan on deploying to iOS, Android and Windows Phone. We have existing data structures used throughout our system (all implementing a common interface) that we would like to store in this manner.</p>
  
  <p><strong>Problem</strong>
  As shown in the code sample, the <code>[ManyToOne]</code> attribute is used to signify a relation field. This does not work. As described on the <a href="https://bitbucket.org/twincoders/sqlite-net-extensions" rel="nofollow">BitBucket Developer Page</a> the <code>[ForeignKey]</code> attribute can be used to specify the foreign key relation. This seemingly only supports an <code>int</code>. Can we easily adapt our structure to support these relations without duplicating the properties for the Id field. e.g. the following is undesirable.</p>
  
  <pre><code>    [ForeignKey(typeof(Address))]
      public int AddressId { set; get; }
  
      [ManyToOne]
      public Address Address
      {
          set { address = value; }
          get { return address; }
      }
  </code></pre>
  
  <p><strong>Code Sample</strong></p>
  
  <pre><code>using SQLite.Net.Attributes;
  using SQLiteNetExtensions.Attributes;
  
  namespace Data
  {
      [Table("Client")]
      public class Client : IData
      {
          private int id = -1;
          private Address address = null;
  
          public Client() { }
  
          public Client(int id)
          {
              this.id = id;
          }
  
          [PrimaryKey, AutoIncrement, Column("_id")]
          public int Id
          {
              set { id = value; }
              get { return id; }
          }
  
          [ManyToOne]
          public Address Address
          {
              set { address = value; }
              get { return address; }
          }
      }
  
      [Table("Address")]
      public class Address : IIdentifiable
      {
          private int id = -1;
          private string someFields = "";
  
          public Address() { }
  
          public Address(int id)
          {
              this.id = id;
          }
  
          [PrimaryKey, AutoIncrement, Column("_id")]
          public int Id
          {
              set { id = value; }
              get { return id; }
          }
  
          public string SomeFields
          {
              set { someFields = value; }
              get { return someFields; }
          }
      }
  }
  </code></pre>