title: How to bind dictionary<string,object> in asp.net core for entity framework?
body: <p>My model includes a property that contains raw json values. I am using entity framework core 3 and dot net core 3.</p>
  
  <pre><code>[Table("test")]
  public class PostData
  {
      [Column("id"), Key]
      public int Id { get; set; }
  
      [Column("name")]
      public string Name { get; set; }
  
      [Column("properties"), JsonExtensionData]
      public virtual Dictionary&lt;string, object&gt; Properties { get; set; } 
  }
  </code></pre>
  
  <p>And I mapped in my db context.</p>
  
  <pre><code>    protected override void OnModelCreating(ModelBuilder modelBuilder)
      {
          base.OnModelCreating(modelBuilder);
  
          modelBuilder.Entity&lt;PostData&gt;(b =&gt;
          {
              b.Property(u =&gt; u.Properties)
                  .HasConversion(
                      d =&gt; JsonConvert.SerializeObject(d),
                      s =&gt; JsonConvert.DeserializeObject&lt;Dictionary&lt;string, object&gt;&gt;(s)
                  )
                  .HasMaxLength(5000)
                  .IsRequired();
          });
      }
  </code></pre>
  
  <p>So When I post a data from asp.net core,</p>
  
  <pre><code>{
      "name": "x",
      "properties": {
          "color": "red",
          "size": "L"
      }
  }
  </code></pre>
  
  <p>Action is:</p>
  
  <pre><code>    [HttpPost("create")]
      public async Task&lt;IActionResult&gt; Create([FromBody] PostData data)
      {
          await using var context = new MyDbContext();
  
          await context.Post.AddAsync(data);
          await context.SaveChangesAsync();
  
          return await Task.FromResult(Ok(data));
      }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/I19Km.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I19Km.png" alt="enter image description here"></a></p>
  
  <p>It saves <code>properties</code> to database like following.</p>
  
  <pre><code>{"color":{"ValueKind":3},"size":{"ValueKind":3}}
  </code></pre>
  
  <p>Why does not serialize?</p>