title: Entity Framework SQLite Foreign Keys works on saving but not reading
body: <p>I have a xamarin application with EF Core 2.0.1 and am having an odd issue with foreign keys not behaving properly in my SQLite database. </p>
  
  <p>It appears that foreign keys works on saving but when i recover the entity the foreign key property will always be null. I've inspected the SQLLIte db file and it has a foreign key constraint on the table and the PRAGMA is enabled. </p>
  
  <p>What am i doing wrong here?</p>
  
  <p><strong>My Model with key</strong></p>
  
  <pre><code>    /// &lt;summary&gt;
      /// The id of the form template
      /// &lt;/summary&gt;
      public int TemplateId { get; set; }
  
      /// &lt;summary&gt;
      /// Link to the template
      /// &lt;/summary&gt;
      [ForeignKey("TemplateId")]
      public virtual FormTemplate FormTemplate { get; set; }
  </code></pre>
  
  <p><strong>The mapped model</strong></p>
  
  <pre><code>    /// &lt;summary&gt;
      /// Identifier for the form template.
      /// This comes from the API.
      /// &lt;/summary&gt;
      [Key]
      public int Id { get; set; }
  </code></pre>
  
  <p><strong>My data context initializer</strong></p>
  
  <pre><code>    /// &lt;summary&gt;
      /// Constructor
      /// &lt;/summary&gt;
      public DatabaseContext(string databaseFilePath)
      {
          DatabaseFilePath = databaseFilePath;
          Database.EnsureCreated(); // Use this in testing so that we don't have to make migrations on every db change
          Database.ExecuteSqlCommand("PRAGMA foreign_keys = ON");
      }
  
      protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
      {
          optionsBuilder.UseSqlite($"Filename={DatabaseFilePath}");
      }
  </code></pre>
  
  <p><strong>here is the SQL schema created when viewing the db</strong></p>
  
  <pre><code>CREATE TABLE `FormsMessages` (
      `Id`    INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
      `TemplateId`    INTEGER NOT NULL,
      CONSTRAINT `FK_FormsMessages_FormTemplates_TemplateId` FOREIGN KEY(`TemplateId`) REFERENCES `FormTemplates`(`Id`) ON DELETE CASCADE
  );
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ID7Nn.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ID7Nn.png" alt="pragma sql db"></a></p>
  
  <p>It appears the SQL BD has the constraint from the EF model. Yet when i try to go through the navigation property the <code>FormTemplate</code> is always <code>null</code> even if i save it with <code>FormTemplate = myinstance</code>. (BTW the database explorer shows the templateId gets populated when i do this.)</p>