title: How to model with EntityFramework extensible fields for the entities
body: <p>I have the following requirement, on my app the Entities will come with some fields, however the user needs to be able to add additional fields to the entity and then values for those fields.</p>
  
  <p>I was thinking something like this but I am not sure if it would be a good approach or not.</p>
  
  <p>The base class is an entity (Not sure which fields I need to add here)</p>
  
  <pre><code>public class Entidad
  {
  }
  </code></pre>
  
  <p>Then the Company Class will inherit from Entity</p>
  
  <pre><code>public class Empresa : Entidad
  {
      [Key]
      public int Id { get; set; }
      public string Nombre { get; set; }
      public string NIT { get; set; }
      public string NombreRepresentanteLegal { get; set; }
      public string TelefonoRepresentanteLegal { get; set; }
      public string NombreContacto { get; set; }
      public string TelefonoContacto { get; set; }
  
      public ICollection&lt;CampoAdicional&gt; CamposAdicionales { get; set; }
  }
  </code></pre>
  
  <p>As you can see there is an ICollection of additional fields. that class would have the fieldname, type and id</p>
  
  <pre><code>public class CampoAdicional
  {
      [Key]
      public int Id { get; set; }
      public string NombreCampo { get; set; }
      public Tiposcampo TipoCampo { get; set; }
  }
  </code></pre>
  
  <p>and then the field value would be something like this:</p>
  
  <pre><code>public class ValorCampo
  {
      public Entidad Entidad { get; set; }
      public CampoAdicional Campo { get; set; }
      public string ValorTexto { get;set ; }
      public int ValorNumerico { get; set; }
  }
  </code></pre>
  
  <p>However I am not sure if this is the correct model classes for my scenario and whether it would create the tables correctly.</p>