title: updating data on one to many relation in EF core
body: <p>I'm trying to update a table(FlightClasses) with multiple rows having relation of one to many with table(Flight) but i can't update it with the changed values
  Can anyone help me with that </p>
  
  <p>Model class of Flight
   i want to update rows on other table of flightclasses linked with row in this table</p>
  
  <pre><code>namespace Airline.Models
  {
      public class FlightModel
      {
          public int Id { get; set; }
          public string FlightName { get; set; }
          public string FlightNo { get; set; }
          public string OriginCity { get; set; }
          public string DestinationCity { get; set; }
          public DateTime Departure { get; set; }
          public DateTime Arrival { get; set; }
          public virtual ICollection&lt;FlightClassesModel&gt; FlightClasses { get; set; }
      }
  }
  </code></pre>
  
  <p>Model class of FlightClasses</p>
  
  <pre><code>namespace Airline.Models
  {
      public class FlightClassesModel
      {
  
          public int FlightClassesModelId { get; set; }
          public type Class { get; set; }
          public int AvailableSeats { get; set; }
          public double Price { get; set; }
          public virtual FlightModel Flight { get; set; }
  
          public int? FlightId { get; set; }
      }
      public enum type
      {
          Business_Class,
          First_Class,
          Club_Class
      }
  }
  </code></pre>
  
  <p>View</p>
  
  <pre><code>@model Airline.Models.FlightModel
  
  @{
      ViewData["Title"] = "Edit";
  }
  
  &lt;h2&gt;Edit&lt;/h2&gt;
  
  &lt;h4&gt;FlightModel&lt;/h4&gt;
  &lt;hr /&gt;
  &lt;div class="row"&gt;
      &lt;div class="col-md-4"&gt;
          &lt;form asp-action="Edit"&gt;
              &lt;div asp-validation-summary="ModelOnly" class="text-danger"&gt;&lt;/div&gt;
              &lt;input type="hidden" asp-for="Id" /&gt;
              &lt;div class="form-group"&gt;
                  &lt;label asp-for="FlightName" class="control-label"&gt;&lt;/label&gt;
                  &lt;input asp-for="FlightName" class="form-control" /&gt;
                  &lt;span asp-validation-for="FlightName" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label asp-for="FlightNo" class="control-label"&gt;&lt;/label&gt;
                  &lt;input asp-for="FlightNo" class="form-control" /&gt;
                  &lt;span asp-validation-for="FlightNo" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label asp-for="OriginCity" class="control-label"&gt;&lt;/label&gt;
                  &lt;input asp-for="OriginCity" class="form-control" /&gt;
                  &lt;span asp-validation-for="OriginCity" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label asp-for="DestinationCity" class="control-label"&gt;&lt;/label&gt;
                  &lt;input asp-for="DestinationCity" class="form-control" /&gt;
                  &lt;span asp-validation-for="DestinationCity" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label asp-for="Departure" class="control-label"&gt;&lt;/label&gt;
                  &lt;input asp-for="Departure" class="form-control" /&gt;
                  &lt;span asp-validation-for="Departure" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label asp-for="Arrival" class="control-label"&gt;&lt;/label&gt;
                  &lt;input asp-for="Arrival" class="form-control" /&gt;
                  &lt;span asp-validation-for="Arrival" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              @foreach (var flightClass in Model.FlightClasses)
              {
                  &lt;div class="form-group"&gt;
                      &lt;label asp-for="@flightClass.Class" class="control-label"&gt;&lt;/label&gt;
                      &lt;select class="form-control" asp-for="@flightClass.Class"  asp-items="Html.GetEnumSelectList&lt;type&gt;()"&gt;&lt;/select&gt;
                      &lt;span asp-validation-for="@flightClass.Class" class="text-danger"&gt;&lt;/span&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label asp-for="@flightClass.AvailableSeats" class="control-label"&gt;&lt;/label&gt;
                      &lt;input asp-for="@flightClass.AvailableSeats" class="form-control" /&gt;
                      &lt;span asp-validation-for="@flightClass.AvailableSeats" class="text-danger"&gt;&lt;/span&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label asp-for="@flightClass.Price" class="control-label"&gt;&lt;/label&gt;
                      &lt;input asp-for="@flightClass.Price" class="form-control" /&gt;
                      &lt;span asp-validation-for="@flightClass.Price" class="text-danger"&gt;&lt;/span&gt;
                  &lt;/div&gt;
              }
  
              &lt;div class="form-group"&gt;
                  &lt;input type="submit" value="Save" class="btn btn-default" /&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div&gt;
      &lt;a asp-action="Index"&gt;Back to List&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>controller</p>
  
  <pre><code>public async Task&lt;IActionResult&gt; Edit(int? id)
          {
              if (id == null)
              {
                  return NotFound();
              }
  
              var flightModel = await _context.Flight.FindAsync(id);
              if (flightModel == null)
              {
                  return NotFound();
              }
              return View(flightModel);
          }
  
  
          [HttpPost]
          [ValidateAntiForgeryToken]
          public async Task&lt;IActionResult&gt; Edit(int id, FlightModel flightModel)
          {
              if (id != flightModel.Id)
              {
                  return NotFound();
              }
  
              if (ModelState.IsValid)
              {
                  try
                  {
                      _context.Update(flightModel);
                      await _context.SaveChangesAsync();
                  }
                  catch (DbUpdateConcurrencyException)
                  {
                      if (!FlightModelExists(flightModel.Id))
                      {
                          return NotFound();
                      }
                      else
                      {
                          throw;
                      }
                  }
                  return RedirectToAction(nameof(Index));
              }
              return View(flightModel);
          }
  </code></pre>