title: Storing System.Version in database with Entity Framework Code First
body: <p>I have a database that is created using Entity Framework 6.1 Code First, I have one specific table I am having issues with.</p>
  
  <p>I have a table called Manifests, the entity definition is below</p>
  
  <pre><code>public class Manifest
  {
      public int Id { get; set; }
      public DateTime ReleaseDate { get; set; }
      public int VersionMajor { get; set; }
      public int VersionMinor { get; set; }
      public int VersionBuild { get; set; }
      public int VersionRevision { get; set; }
      public Version Version
      {
          get
          {
              return new Version(this.VersionMajor, this.VersionMinor, this.VersionBuild, this.VersionRevision);
          }
  
          set
          {
              this.VersionMajor = value.Major;
              this.VersionMinor = value.Minor;
              this.VersionBuild = value.Build;
              this.VersionRevision = value.Revision;
          }
      }
      public string ReleaseNotes { get; set; }
      public bool IsCompulsory { get; set; }
      public string Description { get; set; }
      public string UpdatePackage { get; set; }
  }
  </code></pre>
  
  <p>You will notice that I have a property defined which is a <code>System.Version</code> and will store the manifest version, however, when I run add-migration in the package manager console the resulting migration does not include the <code>Version</code> column.  I have tried setting the <code>modelBuilder.ComplexType&lt;System.Version&gt;()</code> in <code>OnModelCreating</code> but to no avail, please help?</p>
  
  <p>As suggested I have changed the entity definition (see above), but I am now getting an error when running the seed, please see below:</p>
  
  <pre><code>System.Data.Entity.Core.EntityCommandCompilationException: An error occurred while preparing the command definition. See the inner exception for details. ---&gt; System.Data.Entity.Core.MappingException: 
  (6,10) : error 3004: Problem in mapping fragments starting at line 6:No mapping specified for properties Manifest.Version in Set Manifests.
  An Entity with Key (PK) will not round-trip when:
    Entity is type [Drogo.Meera.Data.Context.Manifest]
  </code></pre>
  
  <p>The seed method has the following:</p>
  
  <pre><code>context.Manifests.AddOrUpdate(
      p =&gt; p.Version,
      new Manifest
          {
              Description = "Initial Release",
              VersionMajor = 1,
              VersionMinor = 0,
              VersionBuild = 0,
              IsCompulsory = true,
              ReleaseDate = DateTime.Now,
              ReleaseNotes = "Initial Release",
              UpdatePackage = @"v1-0-0\v1-0-0.zip"
          });
  context.SaveChanges();
  </code></pre>