NHibernate + JSON / Ajax Parent / Child Relationships? Why is this not working?

I have a typical parent / child relationship. Writing news in .NETand adding children works great, NHibernateplays well and adds the right relationship.

However, when passing JSON objectfrom the client to some method that serializes my JSON in the .NET view, NHibernate seems to get confused. It contains the correct query to add the parent (and assigns a new pointer to Id), however it does not associate this parent identifier with the child objects in SQL that it is trying to execute. I came up with a quick and dirty hack, which I will list below. But I was wondering if there is something that I'm missing here?

IList<BackerEntry> backersTemp = new List<BackerEntry>();
foreach (BackerEntry backerEntry in jsonBackerEntity.BackerEntries)
{
  backersTemp.Add(backerEntry);
}

jsonBackerEntity.BackerEntries.Clear();

foreach (BackerEntry backerEntry in backersTemp)
{
  jsonBackerEntity.AddChild(backerEntry);
}

- NHibernate , . AddChild :

public virtual void AddChild(BackerEntry backerEntry)
{
  if (backerEntry.Backer != null)
  {
    backerEntry.Backer.BackerEntries.Remove(backerEntry);
  }
  backerEntry.Backer = this;
  this.BackerEntries.Add(backerEntry);
}

EDIT: , , , , . , JSON. , , - . ( json , , ..)... ?

+3
1

saveOrUpdate Hibernate , . , , , , reset ParentObjects, .

, .

+1

Source: https://habr.com/ru/post/1697638/


All Articles