Entity Framework Set Navigation Property using Reflection
<p>I built an Excel importer that is dynamic. Using reflection, its assigning the values to a new instance of an EF object and adding the EF object to the DbSet. </p>

<pre><code>public class Lease
{
    public int Id { get; set; }
    public int StatusId { get; set; }

    public LeaseStatus { get; set; }
}

public class LeaseStatus
{
    public int Id { get; set; }
    public string Name { get; set; }

    public virtual ICollection&lt;Lease&gt; Leases { get; set; }
}
</code></pre>

<p><strong>PROBLEM:</strong></p>

<p>When setting Lease.LeaseStatus property via reflection, I get a <code>System.Data.Entity.Infrastructure.DbUpdateExceptionback</code> when saving the DbSet.</p>

<p><strong>INNER EXCEPTION:</strong></p>

<p>System.Data.SqlClient.SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Leases_LeaseStatuses". The conflict occurred in database "MyDatabaseName", table "dbo.LeaseStatus", column 'Id'. The statement has been terminated.</p>

<p><strong>QUESTION:</strong></p>

<p>How can I set a navigation property via reflection?
If I'm doing it correctly, what may be causing the Exception?</p>