title: Entity Framework Code First List<string> Property Mapping
body: <p>I am working with Entity Framework Code first. I have a simple model:</p>
  
  <pre><code>public class Variable
  {
      public string Name { get; set; }
  
      public int Id { get; set; }
  
      public IList&lt;string&gt; TextOptions
      {
          get;
          set;
      }
  }
  </code></pre>
  
  <p>I ran into issues with the Property <code>TextOptions</code> being of type <code>List&lt;String&gt;</code>.</p>
  
  <p>When I try to do this in Entity Framework, it does not map.</p>
  
  <p>I found a solution on here (stackoverflow) that fixes my issue. I basically rework my class so that it takes the list and makes it a delimited string which gets persisted instead:</p>
  
  <pre><code>public class Variable : IVariable
  {
      public string Name { get; set; }
  
      public int Id { get; set; }
  
      public virtual IList&lt;string&gt; TextOptions
      {
          get
          {
  
              return _TextOptions;
  
          }
          set
          {
              _TextOptions = value;
          }
      }
  
      private IList&lt;string&gt; _TextOptions;
  
      public string TextOptionsSerialized
      {
          get
          {
              return String.Join(";", _TextOptions);
          }
          set
          {
              _TextOptions = value.Split(new char[]{';'}, StringSplitOptions.RemoveEmptyEntries).ToList();
          }
      }
  }
  </code></pre>
  
  <p>This code works fine. The problem that I have with it is that I think that it violates Separation of Concern. I don't think my model class should be concerned with serializing a list of strings so that Entity framework can persist it.</p>
  
  <p>I ran into a similar issue working in ASP.Net MVC. I had a post sent from the client that would be mapped to a model. There were some issues with the way the model was structured compared to the post. In MVC I could write a Custom Model Binder to handle the conversion in a very safe and reusable fashion.</p>
  
  <p>Is there ANY way I can do this for Entity Framework that is as clean as Custom Model Binders are for MVC?</p>