Search code examples
hibernatenhibernateormfluent-nhibernatefluent-nhibernate-mapping

An association from the table refers to an unmapped class: System.Decimal


There are linkValues accociated with A those are Decimal Value.

public class A
{
    public int Id { get; set; }
    public List<Decimal> LinkValues { get; set; }
}


public class AMap : ClassMap<A>
{
    public AMap()
    {
        Id(x => x.Id).Column("A_Id");

        HasManyToMany<Decimal>(x => x.Links)
                .Table("A_Link_Value_Map")
                .ParentKeyColumn("A_Id")
                .ChildKeyColumn("Link_Value")
                .Cascade.SaveUpdate();
    }
}

I am getting a issue "An association from the table A_Link_Value_Map refers to an unmapped class: System.Decimal". Anyone have any idea or could you please give your thoughts for same.


Solution

  • The mapping HasManyToMany would expect to have entity/object not ValueType - on the other side of many-to-many. Also many-to-many reuires the pairing table.

    The mapping we need here is the HasMany and for ValueType like Decimal we need .Element() mapping:

    HasMany(x => x.Links)
        .Table("A_Link_Value_Map")
        .KeyColumn("A_Id")
        .Element("Link_Value") // Value Type would be an Element
        .Cascade.SaveUpdate();