title: MVC 3 Entity Framework simple mapping of keys
body: <p>Model classes:</p>
  
  <pre><code>public class User {
      [Key]
      public Guid UserId { get; set; }
  
      [Display(Name = "User Name")]
      public string UserName { get; set; }
  
      public virtual ICollection&lt;Asp_Membership&gt; CreateDates { get; set; }
  }
  
  public class Asp_Membership {
      [Key]
      public Guid UserId { get; set; }
  
      [Display(Name = "Date Created")]
      public DateTime CreateDate { get; set; }
  }
  </code></pre>
  
  <p>DbContext</p>
  
  <pre><code>public class UsersContext : DbContext {
          public UsersContext() : base("ApplicationServices") { }
          public DbSet&lt;User&gt; Users { get; set; }
          public DbSet&lt;Asp_Membership&gt; Asp_Memberships { get; set; }
  
          protected override void OnModelCreating(DbModelBuilder modelBuilder) {
             //mapping of Users and Membership
             //what exactly do i put here to join the two tables by UserId
          }
  </code></pre>
  
  <p>My question is a simple one, and as you can probably tell, these are my first attempts into trying to understand how EF actually works. What i am trying to do is join the aspnet_Users table and aspnet_Membership table based on the UserId. How exactly can i do that?</p>
  
  <p>But far more importantly, i really haven't been able to find a good Entity Framework tutorial, any recommendations?</p>
  
  <p>--UPDATE--</p>
  
  <p><strong>DbContext</strong> (same as above)</p>
  
  <p><strong>Model class:</strong></p>
  
  <pre><code>public class User {
      [Key]
      public Guid UserId { get; set; }
  
      [Display(Name = "User Name")]
      public string UserName { get; set; }
  
      public virtual Asp_Membership asp_Membership { get; set; }
  }
  
  public class Asp_Membership {
      [Key]
      public Guid UserId { get; set; }
  
      [Display(Name = "Date Created")]
      public DateTime CreateDate { get; set; }
  }
  </code></pre>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>private UsersContext db = new UsersContext();
  
  // GET: /Users/Index
  public ActionResult Index() {
      return View(db.Users.ToList());
  }
  </code></pre>
  
  <p><strong>Index page:</strong> (with unnecessary elements removed...)</p>
  
  <pre><code>@model IEnumerable&lt;ReservationPro.Models.User&gt;
  ...
  @foreach (var item in Model) {
      &lt;tr&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.UserName)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.asp_Membership.CreateDate)
          &lt;/td&gt;
      &lt;/tr&gt;
  }
  </code></pre>
  
  <p>All i am trying to do is figure out how to join the two separate tables 'aspnet_Users' and 'aspnet_Membership' from the default aspnetdb. As noted in the model class, they both have the column 'UserId'. I know this is a simple question, i'm sorry for making this confusing. As you can probably tell, I have just started with EF and am just trying to get my hands 'dirty' with some simple code.</p>