title: ASP.NET Core 3.1 and Entity Framework Core : one-to-many relationship
body: <p>I am new to Entity Framework Core 3.1 and ASP.NET Core 3.1 in general. What I am trying to do is set up my tables <code>Categories</code>, <code>Manufacturers</code>, <code>Conditions</code>, <code>Locations</code> and <code>AssetFiles</code> to have a one-to-many relationship with my <code>Asset</code> table.</p>
  <p>These are the data models that I have currently</p>
  <p>The <code>Asset</code> table</p>
  <pre><code>public class Asset
  {
          public int Id { get; set; }
          public Categories Category { get; set; }
          public Manufacturers Manufacturer { get; set; }
          public string Model { get; set; }
          public string SerialNumber { get; set; }
          public string PurchasePlace { get; set; }
          public int Quantity { get; set; }
          public DateTime AcquiredDate { get; set; }
          public string PurchasePrice { get; set; } 
          public string CurrentValue { get; set; }
          public Conditions Condition { get; set; }
          public Locations Location { get; set; }
          public AssetFiles Files { get; set; }
  } 
  </code></pre>
  <p><code>Categories</code> table</p>
  <pre><code>public class Categories
  {
          public int Id { get; set; }
          public string CategoryName { get; set; }
          public ICollection&lt;Asset&gt; Assets { get; set; }
  }
  </code></pre>
  <p>The other tables have pretty much the same format. I can create the migration and update the database so that it is created. It looks to me like it is working the way that I want it to.</p>
  <p>My question is how do I access these tables in my Assets controller in the <code>[HttpPost]</code> method to be able to add a category, manufacturer, condition, Location, to the <code>Asset</code> when it is posted cause right now With the controller scaffolded all I'm getting is null for those sections of my asset</p>
  <p>Here is my post method of my <code>assetController</code>:</p>
  <pre><code>[HttpPost]
  public async Task&lt;ActionResult&lt;Asset&gt;&gt; PostAsset([FromForm] Asset asset)
  {
          _context.Assets.Add(asset);
          await _context.SaveChangesAsync();
  
          return CreatedAtAction(&quot;GetAsset&quot;, new { id = asset.Id }, asset);
  }
  </code></pre>
  <p>I'm just looking for a little direction on how I need to look at this to move forward.</p>
  <p>Any help would be appreciated.</p>
  <p>postman submission/result
  <a href="https://i.stack.imgur.com/kEHFV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kEHFV.jpg" alt="enter image description here" /></a></p>
  <p>Edit: 2</p>
  <p>Also just to mention I am using a VueJs Front End not sure if that matters to the tips you are giving or if accessing the data is the same .</p>