While I realize that this is an old question, the answers didn't resolve my issue with EF 6.
For EF 6 you need to create a ComplexTypeConfiguration Mapping.
example:
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.
DbContext.OnModelCreating
yet? DoesmodelBuilder.Entity<Product>().Ignore(p => p.AddressDetails.Country)
in that method fail? – GerhartProduct.AddressDetail
. It obviously has a different behavior from theAddressDetail
used elsewhere. – BraidAddressDetail
is a Complex Type and is made to be shared across. A solution would be to create a base classAddressDetail
and then create two new classes that inherits from it:UserAddress
andProductAddress
but i was trying to avoid this. – RexfourdCountry != null
and run it againstProduct.AddressDetail
it would throw. Therefore LSP was violated. PS. Less classes does not equal simple. In your case you have created a new edge case, which is not KISS. – Braid