I have the following classes and mappings:
public enum VariationType
{
Base = 1,
RiderMain = 2,
RiderSpouse = 3,
RiderChild = 4,
Family = 5,
FamilyBase = 6
}
public class PlanParameter
{
private IDictionary<VariationType, PlanParameterDefaultValue> _defaultValues;
public PlanParameter()
{
ParameterContext = new Parameter();
}
public virtual Parameter ParameterContext { get; set; }
public virtual object DefaultValue { get; set; }
public virtual string DefaultValueString
{
get
{
return DefaultValue == null ? null : DefaultValue.ToString();
}
set
{
DefaultValue = value == null ? null : Convert.ChangeType(value, ParameterContext.Type);
}
}
public virtual IDictionary<VariationType, PlanParameterDefaultValue> DefaultValues
{
get
{
if (_defaultValues == null)
_defaultValues = new Dictionary<VariationType, PlanParameterDefaultValue>();
return _defaultValues;
}
}
}
class PlanParameterMap : ClassMap<PlanParameter>
{
public PlanParameterMap()
{
Id().GeneratedBy.Identity().Column("ID");
References(x => x.ParameterContext,"ParameterID");
Map(x => x.DefaultValueString);
HasMany(x=> x.DefaultValues)
.Access.CamelCaseField(Prefix.Underscore)
.KeyColumn("PlanParameterID").Inverse()
.AsMap("Variation")
.Cascade.AllDeleteOrphan();
}
}
public class PlanParameterDefaultValue
{
public virtual PlanParameter PlanParameter { get; set; }
public virtual object DefaultValue { get; set; }
public virtual string DefaultValueString
{
get
{
return DefaultValue == null ? null : DefaultValue.ToString();
}
set
{
DefaultValue = value == null ? null : Convert.ChangeType(value, PlanParameter.ParameterContext.Type);
}
}
}
class PlanParameterDefaultValueMap : ClassMap<PlanParameterDefaultValue>
{
public PlanParameterDefaultValueMap()
{
Id().GeneratedBy.Identity().Column("ID");
Map(x => x.DefaultValueString);
References(x => x.PlanParameter).Column("PlanParameterID");
}
}
My problem is very specific to the mapping of the
IDictionary<VariationType, PlanParameterDefaultValue> DefaultValues
The enum for some reason will not save, all that's saved in it's column is null my only solution so far was to add a VariationType Property to the Entity and map it with a lambda formula, but i really don't need the VariationType in the Entity
Am i doing something wrong?
Thanks very much