title: Storing/retrieving a JSON string in the database making it easy to work with in code
body: <p>I have a c# object 'Product' with a property called: Offset<br>
  In the database the field is of type nvarchar(50)</p>
  
  <p>I will be storing a JSON value in it such as the following: { "y": 0, "m": 0, "d": 0 }</p>
  
  <p>I would like to know a good way of working with a property like this in my code. Here is how I currently am doing it:</p>
  
  <pre><code>public class Product 
  {
      public int Id {get; set;}
      public string Description {get; set;}
      public decimal Price {get; set;}
  
      public int OffsetYears { get; set; }
      public int OffsetMonths { get; set; }
      public int OffsetDays { get; set; }
  
      public string Offset
      {
          get
          {
              Offset offset = new Offset()
              {
                  Y = OffsetYears,
                  M = OffsetMonths,
                  D = OffsetDays
              };
  
              return JsonConvert.SerializeObject(offset);
          }
          set
          {
              OffsetObj offset = JsonConvert.DeserializeObject&lt;Offset&gt;(value);
  
              OffsetYears = offset.Y;
              OffsetMonths = offset.M;
              OffsetDays = offset.D;
          }
      }
  
      private class OffsetObj
      {
          public int Y { get; set; }
          public int M { get; set; }
          public int D { get; set; }
      }   
  }
  </code></pre>
  
  <p>So then when I accept values from the User in the UI I would set the OffsetYears, OffsetMonths, and OffsetDays properties.. So in my repository I can just save Offset.</p>
  
  <p>And when retrieving values from the database I will simply work with OffsetYears, OffsetMonths, and OffsetDays properties in my code.</p>
  
  <p>Is there a better way to handle this sort of thing? I just feel like I am not utilizing all of my c# resources. Like what if another developer accidentally sets Offset through the code assuming any format of string can go in it.</p>
  
  <p>Or am I better off just creating 3 separate integer fields in the database and avoiding all of this...</p>