I have a class, Item that has many Rates. They are keyed by an enum, RateType.
public class Item
{
int Id {get;set;}
IDictionary<RateType, Rate> Rates {get;set;}
// some other stuff
}
public class Rate
{
RateType Type {get;set;}
decimal Amount {get;set;}
decimal Quantity {get;set;}
}
I am overriding my mapping thusly:
public void Override(FluentNHibernate.Automapping.AutoMapping<Item> mapping)
{
mapping.HasMany(x => x.Rates)
.AsMap(x => x.Type)
.KeyColumns.Add("Item_Id")
.Table("InvoiceItem_Rates")
.Component(x => x.Map(r => r.Amount))
.Component(x => x.Map(r => r.Quantity))
.Cascade.AllDeleteOrphan()
.Access.Property();
}
This has two problems with it.
1) When I fetch an item, the Type is placed as the key of the Dictionary without problems. However, it is not assigned to the Type property within the Rate.
2) I'm expecting three columns in the table InvoiceItem_Rates (Item_Id, Type, Quantity, and Amount. However, Amount is suspiciously absent.
Why are these things happening? What am I doing wrong?