WhatChanged() always contains RemovedField for property "Id"

67 views
Skip to first unread message

Tobias B

unread,
Aug 3, 2020, 12:39:54 PM8/3/20
to RavenDB - 2nd generation document database
Hi,

we are using this workaround see here https://issues.hibernatingrhinos.com/issue/RavenDB-14227 


Unfortunatly this workaround has the side effect that whenever we get an entity from ravendb we have a change, even when we do not change anything :-/
As we need the workaround, is there a way to get WhatChanged to work in my setup?




((DocumentStore)documentStore).OnAfterConversionToDocument += (s, e) =>
{
   e.Document.Modifications = new DynamicJsonValue(e.Document)
   {
       ["Id"] = e.Id
   };
};


using (var _session = store.OpenAsyncSession()) { var bewerber = await _session.Query<Entity>().FirstOrDefaultAsync(); if (_session.Advanced.HasChanged(bewerber)) { // whatChanged always contains one change "RemovedField" for property Id var whatChanged = _session.Advanced.WhatChanged(); } }



Egor Shamanaev

unread,
Aug 9, 2020, 2:13:26 AM8/9/20
to rav...@googlegroups.com
Hi,

I think you can register a jsonconverter and not modify the doc, that should not fire the changes api.

--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ravendb/68bb2ea6-8a33-42ae-937c-a438e795d85do%40googlegroups.com.


--
Egor
Developer   /   Hibernating Rhinos LTD
Support:  sup...@ravendb.net
  

Tobias B

unread,
Aug 10, 2020, 2:41:48 AM8/10/20
to RavenDB - 2nd generation document database
Hello Egor,

thanks for your response. I am a little stumped on the json converter. What should this converter do?


Am Sonntag, 9. August 2020 08:13:26 UTC+2 schrieb Egor Shamanaev:
Hi,

I think you can register a jsonconverter and not modify the doc, that should not fire the changes api.

On Mon, Aug 3, 2020 at 7:40 PM 'Tobias B' via RavenDB - 2nd generation document database <rav...@googlegroups.com> wrote:
Hi,

we are using this workaround see here https://issues.hibernatingrhinos.com/issue/RavenDB-14227 


Unfortunatly this workaround has the side effect that whenever we get an entity from ravendb we have a change, even when we do not change anything :-/
As we need the workaround, is there a way to get WhatChanged to work in my setup?




((DocumentStore)documentStore).OnAfterConversionToDocument += (s, e) =>
{
   e.Document.Modifications = new DynamicJsonValue(e.Document)
   {
       ["Id"] = e.Id
   };
};


using (var _session = store.OpenAsyncSession()) { var bewerber = await _session.Query<Entity>().FirstOrDefaultAsync(); if (_session.Advanced.HasChanged(bewerber)) { // whatChanged always contains one change "RemovedField" for property Id var whatChanged = _session.Advanced.WhatChanged(); } }



--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rav...@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Aug 10, 2020, 5:50:10 AM8/10/20
to ravendb
This should fix this issue, I think:

To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ravendb/29f299fb-65dd-4838-8c8d-cb12c3c49499o%40googlegroups.com.


--
Oren Eini
CEO   /   Hibernating Rhinos LTD
Skype:  ayenderahien
Support:  sup...@ravendb.net
  

Tobias B

unread,
Aug 10, 2020, 7:27:57 AM8/10/20
to RavenDB - 2nd generation document database
Hi Oren,

thanks or that. I give this a try once the nighly´s are up.
Message has been deleted

Egor Shamanaev

unread,
Aug 13, 2020, 3:24:01 AM8/13/20
to rav...@googlegroups.com
Hi

What are those commands?

On Mon, Aug 10, 2020 at 3:40 PM 'Tobias B' via RavenDB - 2nd generation document database <rav...@googlegroups.com> wrote:
and the commands attached (got an error in my original reply with this file 

--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ravendb/8d60fa8e-d7b1-46a8-ac89-b83c525d9a0do%40googlegroups.com.

Tobias B

unread,
Aug 13, 2020, 3:46:55 AM8/13/20
to RavenDB - 2nd generation document database
Hi Egor,

from another thread of me (CPU @30%). The upload from google groups did not work, and i confused the tabs. I realized some seconds after and deleted the post.
Sorry for that!

Am Donnerstag, 13. August 2020 09:24:01 UTC+2 schrieb Egor Shamanaev:
Hi

What are those commands?

On Mon, Aug 10, 2020 at 3:40 PM 'Tobias B' via RavenDB - 2nd generation document database <rav...@googlegroups.com> wrote:
and the commands attached (got an error in my original reply with this file 

--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rav...@googlegroups.com.

tobias.man...@googlemail.com

unread,
Jan 18, 2021, 9:45:21 AM1/18/21
to RavenDB - 2nd generation document database
Hi,

okay i know this is an older ticket, but the code you changed is now in 5.1 (as far as i see) but i still have the same behavoir

whatchanged.png

Server and Client running on 5.1.2

Oren Eini (Ayende Rahien)

unread,
Feb 1, 2021, 7:05:19 AM2/1/21
to ravendb
Are you sure you updated your client dlls?

tobias.man...@googlemail.com

unread,
Aug 12, 2024, 5:02:43 AMAug 12
to RavenDB - an awesome database

While revisiting some old code, I came across this workaround from a previous discussion. After testing, I can confirm that the behavior still persists in RavenDB 6.0.105.

Below is a complete test to demonstrate this.

'''
using Raven.Client.Documents.Queries;
using Raven.Embedded;
using Sparrow.Json.Parsing;
using System;
using System.Linq;
using Xunit;

public class UnitTest8_IDs
{
    [Fact]
    public void CollationTest()
    {
        EmbeddedServer.Instance.StartServer();
        using var store = EmbeddedServer.Instance.GetDocumentStore("id-storage");

        store.OnAfterConversionToDocument += (s, e) =>

        {
            e.Document.Modifications = new DynamicJsonValue(e.Document)
            {
                ["Id"] = e.Id
            };
        };

        string idParent = "EntityWithChild/1";
        string idChild = "ChildEntity/1";

        #region Create Entities
        using (var session = store.OpenSession())
        {
            var child = new ChildEntity { Name = "Child", Id = idChild };
            var parent = new EntityWithChild { Name = "Parent", ChildEntityId = child.Id, Id = idParent };

            session.Store(child);
            session.Store(parent);
            session.SaveChanges();

            Assert.Equal(idParent, parent.Id);
            Assert.Equal(idChild, child.Id);
            Assert.Equal(idChild, parent.ChildEntityId);
        }
        #endregion

        #region Verify OnAfterConversionToDocument Workaround
        using (var session = store.OpenSession())
        {
            var parentFromDb = (from parent in session.Query<EntityWithChild>()
                                let child = RavenQuery.Load<ChildEntity>(parent.ChildEntityId)
                                select new
                                {
                                    Parent = parent,
                                    Child = child
                                }).First();

            Assert.Equal(idChild, parentFromDb.Child.Id);
            Assert.Equal(idParent, parentFromDb.Parent.Id);

            Assert.False(session.Advanced.WhatChanged().Any());
        }
        #endregion

        #region WhatChanged shows Removed Property of "Id"
        using (var session = store.OpenSession())
        {
            var parent = session.Load<EntityWithChild>(idParent);
            var child = session.Load<ChildEntity>(idChild);

            var whatChanged = session.Advanced.WhatChanged();

            Assert.Equal(0, whatChanged.Count); // Fails, two entries with "RemovedField"
        }
        #endregion
    }

    class EntityWithChild : BaseEntity
    {
        public string Name { get; set; }
        public string ChildEntityId { get; set; }
    }

    class ChildEntity : BaseEntity
    {
        public string Name { get; set; }
    }

    public abstract class BaseEntity
    {
        public string Id { get; set; }

        protected BaseEntity()
        {
            Id = $"{GetCollectionName()}/{Guid.NewGuid()}";
        }

        protected virtual string GetCollectionName()
        {
            return GetType().Name;
        }
    }
}
'''

Oren Eini
Skype:  ayenderahienSupport:  sup...@ravendb.net
  

--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
Oren Eini

CEO   /   Hibernating Rhinos LTD
Skype:  ayenderahienSupport:  sup...@ravendb.net
  
Reply all
Reply to author
Forward
0 new messages