0

I have the following classes:

public class PhoneModel
{
     public virtual ModelIdentifier SupportModels
}
public class ModelIdentifier
{
     public virtual string Name
     public virtual IList<string> Values
}

This is how i mapped it:

      mapping.Component(x => x.SuppoertedModel, y =>
      {
        y.Map(x => x.Name, "FAMILY_ID");
        y.HasMany(x => x.Values).Element("VALUE").Table("SUPPORTEDMODULS")
      }

2 tables were created:

  1. PhoneModel column "FAMILY_ID"
  2. SUPPORTEDMODELS column "VALUE", "PHONE_MODEL_ID"

The problem is that when I am adding values, it will not save it to the SUPPORTEDMODELS table:

var pm = new PhoneModel();
pm.SupportedModels.Name = "11"
pm.SupportedModels.Values.Add("34");
James Zalame
  • 183
  • 2
  • 11

1 Answers1

0
  • you are missing HasMany(x => x.Values).Cascade.AllDeleteOrphan()
  • maybe session.Flush() or transaction.Commit() is missing in the test code

btw: if the order of the Values is not important then change it to ICollection<string> and HasMany().AsSet() since this allows NH to optimise some things and code can not rely on the order which is not relyable when using sql.

Firo
  • 30,626
  • 4
  • 55
  • 94