I have a database that is created using Entity Framework 6.1 Code First, I have one specific table I am having issues with.
I have a table called Manifests, the entity definition is below
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; }
}
You will notice that I have a property defined which is a System.Version and will store the manifest version, however, when I run add-migration in the package manager console the resulting migration does not include the Version column. I have tried setting the modelBuilder.ComplexType<System.Version>() in OnModelCreating but to no avail, please help?
As suggested I have changed the entity definition (see above), but I am now getting an error when running the seed, please see below:
System.Data.Entity.Core.EntityCommandCompilationException: An error occurred while preparing the command definition. See the inner exception for details. ---> 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]
The seed method has the following:
context.Manifests.AddOrUpdate(
p => 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();
Versioncolumn, it should create multiple columns with names likeVersion_MajorandVersion_Minor. - jjjManifest.Version-- I didn't think you would need to. UsemodelBuilder.Entity<Manifest>().Ignore(m => m.Version);- jjj