title: Adding array of int to database in Entity Framework Core
body: <p>I want to make an API that can receive any number of child IDs.
  and loop it in database adding 1 row for each child IDs. 
  I tried making the CategoryChildId a list or array but it says Entity framework does not accept primitive types.</p>
  
  <p>How can i achieve this?</p>
  
  <p>for example when i receive a json like this:</p>
  
  <pre><code>"CategoryParentID": "4",
  "CategoryChildID": [
      {
        5,6,7
      }
    ],
  </code></pre>
  
  <p>It will store it in database like this.</p>
  
  <p><a href="https://i.stack.imgur.com/3KTYI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3KTYI.png" alt="enter image description here"></a></p>
  
  <p>I only have the code for adding single child at a time. </p>
  
  <p>The service for the controller:</p>
  
  <pre><code> public async Task&lt;ServiceResultWithoutBaseEntity&lt;CategoryRollup&gt;&gt; Add(CategoryRollupViewModel newItem)
  {
      var result = new ServiceResultWithoutBaseEntity&lt;CategoryRollup&gt;();
      result.Errors.AddRange(Validate(newItem));
  
      if (result.HasErrors)
          return result;
  
      var item = newItem.MapToEntity(new CategoryRollup());
  
      _context.CategoryRollups.Add(item);
      await _context.SaveChangesAsync();
  
      result.EntityResult = item;
  
      return result;
  }
  </code></pre>
  
  <p>model: </p>
  
  <pre><code>    public class CategoryRollup
  {
      [Key]
      public int ID { get; set; }
  
      public int CategoryChildID { get; set; }
  
      public int CategoryParentID { get; set; }
  }
  </code></pre>
  
  <p>view model:</p>
  
  <pre><code>public class CategoryRollupViewModel
  {
      [Key]
      public int ID { get; set; }
  
      public int CategoryChildID { get; set; }
  
      public int CategoryParentID { get; set; }
  
  }
  </code></pre>
  
  <p>helper:</p>
  
  <pre><code>  public static class CategoryRollupHelper
  {
      public static CategoryRollupViewModel MapFromEntity(this CategoryRollup source)
      {
          if (source == null)
              return null;
  
          var result = new CategoryRollupViewModel
          {
              CategoryChildID = source.CategoryChildID,
              CategoryParentID = source.CategoryParentID,
          };
  
          return result;
      }
  
      public static CategoryRollup MapToEntity(this CategoryRollupViewModel source, CategoryRollup entity)
      {
          if (source == null || entity == null)
              return null;
  
          entity.CategoryChildID = source.CategoryChildID;
          entity.CategoryParentID = source.CategoryParentID;
  
          return entity;
      }
  }
  </code></pre>