虽然我意识到这是一个老问题,但答案并没有解决我对 EF 6 的问题。
对于 EF 6,您需要创建一个 ComplexTypeConfiguration 映射。
例子:
public class Workload
{
public int Id { get; set; }
public int ContractId { get; set; }
public WorkloadStatus Status {get; set; }
public Configruation Configuration { get; set; }
}
public class Configuration
{
public int Timeout { get; set; }
public bool SaveResults { get; set; }
public int UnmappedProperty { get; set; }
}
public class WorkloadMap : System.Data.Entity.ModelConfiguration.EntityTypeConfiguration<Workload>
{
public WorkloadMap()
{
ToTable("Workload");
HasKey(x => x.Id);
}
}
// Here This is where we mange the Configuration
public class ConfigurationMap : ComplexTypeConfiguration<Configuration>
{
ConfigurationMap()
{
Property(x => x.TimeOut).HasColumnName("TimeOut");
Ignore(x => x.UnmappedProperty);
}
}
If your Context is loading configurations manually you need to add the new ComplexMap, if your using the FromAssembly overload it'll be picked up with the rest of the configuration objects.