title: Query with linq from database
body: <p>I'm doing an <em>mvc</em> Theater project with entity framework code first.<br>
  I created a page to add a movie to my database.<br>
  the Movie class has a <em>Genre</em> property,the <em>Genre</em> class has an Id and a Name property.<br>
  What I'm trying to do is query all rows of the Genres table from database with <code>Linq</code> <em>(if other method is better do tell)</em> and choose one <em>Genre</em> to connect to a row of the movie I'm creating.</p>
  
  <p>thanks,any help is appreciated.</p>
  
  <p>this is my Genre class</p>
  
  <pre><code>public class Genre
  {
      [Key]
      public int Id { get; set; }
      [Display(Name="Ganre")]
      public string GenreName { get; set; }
      public virtual ICollection&lt;Movie&gt; MoviesByGenre { get; set; }
  }
  </code></pre>
  
  <p>this is my Movie class</p>
  
  <pre><code>public class Movie
  {
      [Key]
      public string Id { get; set; }
      [Required(ErrorMessage = "Movie name is required")]
      [Display(Name="Movie name")]
      public string MovieName { get; set; }
      [Required(ErrorMessage = "Movie length is required")]
      [Display(Name="Length(minutes)")]
      public int LengthInMinutes { get; set; }
      [Required(ErrorMessage="Genre of the movie is required")]
      [Display(Name="Genre")]
      public virtual Genre MovieGenre { get; set; }
      public string Description { get; set; }
      [Required(ErrorMessage = "Year of release is required")]
      public int Year { get; set; }
      [Required(ErrorMessage="Who is the director?")]
      public virtual MovieDirector Director { get; set; }
      public virtual MoviePoster Poster { get; set; }
  
      //How many users bought a ticket
      public virtual ICollection&lt;ApplicationUser&gt; UsersWhoBoughtTicket { get; set; }
  }
  </code></pre>
  
  <p>this is the Add Movie page</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="form-horizontal"&gt;
          &lt;h4&gt;Movie&lt;/h4&gt;
          &lt;hr /&gt;
          @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.MovieName, htmlAttributes: new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(model =&gt; model.MovieName, new { htmlAttributes = new { @class = "form-control" } })
                  @Html.ValidationMessageFor(model =&gt; model.MovieName, "", new { @class = "text-danger" })
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.LengthInMinutes, htmlAttributes: new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(model =&gt; model.LengthInMinutes, new { htmlAttributes = new { @class = "form-control" } })
                  @Html.ValidationMessageFor(model =&gt; model.LengthInMinutes, "", new { @class = "text-danger" })
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.Description, htmlAttributes: new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(model =&gt; model.Description, new { htmlAttributes = new { @class = "form-control" } })
                  @Html.ValidationMessageFor(model =&gt; model.Description, "", new { @class = "text-danger" })
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.Year, htmlAttributes: new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(model =&gt; model.Year, new { htmlAttributes = new { @class = "form-control" } })
                  @Html.ValidationMessageFor(model =&gt; model.Year, "", new { @class = "text-danger" })
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.MovieGenre.GenreName, htmlAttributes: new { @class = "btn control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.ValidationMessageFor(model =&gt; model.MovieGenre.GenreName, "", new { @class = "text-danger" })
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.Director, htmlAttributes: new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(model =&gt; model.Director, new { htmlAttributes = new { @class = "form-control dropdown" } })
                  @Html.ValidationMessageFor(model =&gt; model.Director, "", new { @class = "text-danger" })
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.Poster, new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  &lt;input name="Image" type="file" /&gt;
                  @Html.ValidationMessageFor(model =&gt; model.Poster)
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              &lt;div class="col-md-offset-2 col-md-10"&gt;
                  &lt;input type="submit" value="Create" class="btn btn-default" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>