Consider the following models/mappings

    [DataContract]
    public class CustomPhrase : ModelBase
    {
      private ICollection<EnglishPhrase> translations;

      public CustomPhrase()
      {
        this.translations = new List<EnglishPhrase>();
      }

      [DataMember]
      public virtual string Phrase { get; set; }

      [DataMember]
      public virtual IEnumerable<EnglishPhrase> Translations
      {
        get
        {
          return this.translations;
        }
      }
    }

    [DataContract]
    public class EnglishPhrase : ModelBase
    {
      private ICollection<CustomPhrase> translations;

      public CustomPhrase()
      {
        this.translations = new List<CustomPhrase>();
      }

      [DataMember]
      public virtual string Phrase { get; set; }

      [DataMember]
      public virtual IEnumerable<CustomPhrase> Translations
      {
        get
        {
          return this.translations;
        }
      }
    }

    public CustomPhraseMap() : base("Translation_CustomPhrase",
"CustomPhraseId")
    {
      this.Property(x => x.Phrase);
      this.Set(
        x => x.Translations,
        map =>
          {
            map.Table("Translation_Link");
            map.Key(key => key.Column("CustomPhraseId"));
            map.Access(Accessor.Field);
            map.Cascade(Cascade.All);
          },
        map => map.ManyToMany(c => c.Column("EnglishPhraseId"))
        );
    }

    public EnglishPhraseMap() : base("Translation_EnglishPhrase",
"EnglishPhraseId")
    {
      this.Property(x => x.Phrase);
      this.Set(
        x => x.Translations,
        map =>
          {
            map.Table("Translation_Link");
            map.Key(key => key.Column("EnglishPhraseId"));
            map.Access(Accessor.Field);
            map.Cascade(Cascade.All);
          },
        map => map.ManyToMany(c => c.Column("CustomPhraseId"))
        );
    }

If I execute this bit of code, the entities are added to the database
but the link table `Translation_Link` is not updated.

    var customPhrase = new CustomPhrase { Phrase = "Gobble" };
    var englishPhrase = new EnglishPhrase { Phrase = "Hello" };
    customPhrase.AddTranslation(englishPhrase);
    this.customPhraseRepository.Add(customPhrase);

I'm not sure if this is a mapping problem, or a repository
configuration problem. Maybe I'm adding the child at the wrong time??

Has anyone else come across this problem before and been able to fix
it?

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to