Ignore one property of a complex type

c# ef-code-first entity-framework entity-framework-6

Question

I want to ignore one property of a complex type for mapping to the database where FinalTotal is a computed field. Entity Framework says that it isn't allowed and that it must be a property. :(

public class Sale
{
     public int      Id { get; set; }
     public DateTime DateSale { get; set; }
     public Amounts  Amounts { get; set; }
}

public class Amounts
{
     public decimal Subtotal { get; set; }
     public decimal Tax { get; set; }
     public decimal FinalTotal { get; set; }
}

public class SaleMap : EntityTypeConfiguration<Sale>
{
     public SaleMap()
     {
          Ignore(s => s.Amounts.FinalTotal);
     }
}
1
3
7/13/2014 3:26:48 PM

Accepted Answer

public class AmountsMap : EntityTypeConfiguration<Amounts>
{
     public AmountsMap()
     {
          Ignore(a => a.FinalTotal);
     }
}
7
7/13/2014 3:34:00 PM

Popular Answer

If a property has no setter, it will not be mapped to a database column. If it's a calculated field you can let it have only a getter with the calculation.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow