Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, the problem here lies in the fact that using the Json.NET Deserializer in a normal capacity essentially creates a new object - this object is then persisted by NHibernate. The end result is the record in the database is kept, as are all the child objects that exist in the new child object collection - however children that were removed are orphaned - since the where not removed directly from the persisted NHibernate object using .Remove or .Clear.</p> <p>The solution is in two parts. Firstly, we have to use the <code>CustomCreationConverter</code> of Json.NET to pass in an instance of the existing object to be worked on (merge). </p> <pre><code> public static T Deserialize&lt;T&gt;(T existingObject, string json) { return JsonConvert.DeserializeObject&lt;T&gt;(json, new ObjectConverter&lt;T&gt;(existingObject)); } public class ObjectConverter&lt;T&gt; : CustomCreationConverter&lt;T&gt; { public T ExistingObject { get; set; } public ObjectConverter(T existingObject) { ExistingObject = existingObject; } public override T Create(Type objectType) { return ExistingObject; } } </code></pre> <p>This alone will not work however, as the exiting objects child collections will be <em>added to</em> by the children in the json collection. The remedy this, and to ensure that NHibernate knows what to do when receiving the resulting object, we need to do a bit of a Json.NET hack.</p> <p>Json.Net > Serialization > JsonSerializerInternalReader.cs</p> <pre><code>private object PopulateList(IWrappedCollection wrappedList, JsonReader reader, string reference, JsonArrayContract contract) { // Edit // Clear the collection wrappedList.Clear(); </code></pre> <p>After re-compiling, and re-adding the DLL - it works - children that are removed in javascript are finally removed from the DB as well.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload