title: ASP.NET MVC 4 Entity Framework entity to get foreign key field from membership user profile table
body: <p>I have entities in a separate project. One of the entity needs to refer a <code>UserId</code> in <code>UserProfile</code> model in the <code>Web</code> project which is already referencing <code>Entity</code> project. Anybody can help to get a new foreign key to my entity (something like <code>Expense</code> entity class to get additional field <code>Expender</code> which is already a primary key in <code>UserProfile</code> which is a membership table?)</p>
  
  <pre><code>namespace ExpenseAssistant.Entities
  {
      /// &lt;summary&gt;
      /// Expense
      /// &lt;/summary&gt;
      public class ExpenseEntry
      {
          /// &lt;summary&gt;
          /// Gets or sets Unique Id of the Expense
          /// &lt;/summary&gt;
          public virtual int Id { get; set; }
  
          /// &lt;summary&gt;
          /// Gets or sets Description about the Expense
          /// &lt;/summary&gt;
          public virtual string ExpenseDescription { get; set; }
  
          /// &lt;summary&gt;
          /// Gets or sets the Amount Spent
          /// &lt;/summary&gt;
          public virtual float Amount { get; set; }
  
          /// &lt;summary&gt;
          /// Gets or sets the Expender which is the UserId from UserProfile Table
          /// &lt;/summary&gt;
          [ForeignKey("UserProfile")]
          public virtual int ExpenderId { get; set; }
      }
  }
  </code></pre>
  
  <p>Membership tables are in the same database in which I have all the entity tables.</p>
  
  <p>I tried with <code>update-database</code> in console after adding this key <code>ExpenderId</code> in <code>ExpenseEntry</code> entity, I am getting the error as below,</p>
  
  <blockquote>
    <p>The ForeignKeyAttribute on property 'ExpenderId' on type
    'ExpenseAssistant.Entities.ExpenseEntry' is not valid. The navigation
    property 'UserProfile' was not found on the dependent type
    'ExpenseAssistant.Entities.ExpenseEntry'. The Name value should be a
    valid navigation property name.</p>
  </blockquote>
  
  <p>Thanks in advance.</p>