title: What is the proper way to Join two tables in ASP.NET MVC?
body: <p>I've been working on a simple Dropbox-like app, to learn some ASP.NET MVC. But even before getting a page working decently I've gotten stuck, and there's so much info out there I can't see the forest for the trees anymore.</p>
  
  <p>My situation:</p>
  
  <p>I want to show on a page all the files in a certain folder belonging to a certain person. I've designed my database beforehand and then generated a Code First EF model from that. The relevant part of the database is below. Note that <code>AspNetUsers</code> is part of MVC5 Identity. Linking <code>Identity</code> to my own tables seems to be the hardest part, since the tables belonging to <code>Identity</code> are implemented in IdentityModels, while my tables are implemented in TADModels.</p>
  
  <p><img src="https://i.stack.imgur.com/ad6Zg.png" alt="enter image description here"></p>
  
  <p>I've been following various tutorials on <a href="http://www.asp.net/mvc/overview/getting-started/introduction/getting-started" rel="nofollow noreferrer">this page</a>, but can't seem to find anything that helps me accomplish what I need. I'm basically just trying to execute the following query:</p>
  
  <pre><code>SELECT f.FileName, f.FileSize
  FROM Files f
  INNER JOIN FileTree ft ON ft.FolderID = f.FolderID
  INNER JOIN AspNetUsers u ON ft.UserID = u.Id
  WHERE u.id = @id AND ft.FolderPath = @path;
  </code></pre>
  
  <p>According to one of the aforementioned tutorials, I'm supposed to be able to do something along the lines of:</p>
  
  <pre><code>namespace TAD.Models
  {
      using System;
      using System.Collections.Generic;
      using System.ComponentModel.DataAnnotations;
      using System.ComponentModel.DataAnnotations.Schema;
      using System.Data.Entity.Spatial;
  
      [Table("FileTree")]
      public partial class FileTree
      {
          [Key]
          public string FolderID { get; set; }
  
          [Required]
          [StringLength(128)]
          public string UserID { get; set; }
  
          [Required]
          [StringLength(255)]
          public string FolderName { get; set; }
  
          [Required]
          [StringLength(255)]
          public string FolderPath { get; set; }
  
          public virtual ICollection&lt;File&gt; Files { get; set;  }
  
          public virtual ApplicationUser user { get; set; }
      }
  }
  </code></pre>
  
  <p>The Files Collection is supposed to find the files associated with the path, and user is supposed to find the user associated with the path. But during Scaffolding I get errors along the lines of <code>TAD.Models.IdentityUserRole: EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType'</code>. Which I suppose is happening because of <code>ApplicationUSer user</code></p>
  
  <p>This question seems very confusing, even to me. I simply don't know what I'm looking for. The tutorials I mentioned present situations too simple for my needs, while other info is much too advanced.</p>
  
  <p><strong>EDIT: This is the File Model:</strong></p>
  
  <pre><code>namespace TAD.Models
  {
      using System;
      using System.Collections.Generic;
      using System.ComponentModel.DataAnnotations;
      using System.ComponentModel.DataAnnotations.Schema;
      using System.Data.Entity.Spatial;
  
      public partial class File
      {
          [Key]
          public string FileID { get; set; }
  
          [Required]
          [StringLength(128)]
          public string UserID { get; set; }
  
          [Required]
          [StringLength(128)]
          public string FolderID { get; set; }
  
          [Required]
          [StringLength(255)]
          public string FileName { get; set; }
  
          public decimal FileSize { get; set; }
  
          public bool IsPublic { get; set; }
          public virtual ApplicationUser user { get; set; }
  
          public virtual FileTree folder { get; set; }
      }
  }
  </code></pre>