Add IMetadataDictionary to @metadata

71 views
Skip to first unread message

marcus

unread,
Feb 22, 2018, 10:15:33 AM2/22/18
to RavenDB - 2nd generation document database
Is it possible to group metadata properties in a complex object or maybe in a IMetadataDictionary inside of @metadata?

Let's say I would like to add something like this:

"@metadata": {
  "@collection": "Abouts",
  "Raven-Clr-Type": "src.Models.About, src",
  "@capabilities": {
    "Culture": "en",
    "Name": "foo",
    "Url": "/bar"
  }
}

There is a method called IMetadataDictionary.GetObject(string key) so I guess it's possible to add a IMetadataDictionary inside the @metadata? I can't find any implementation of IMetadataDictionary though?

marcus

unread,
Feb 23, 2018, 7:27:13 AM2/23/18
to RavenDB - 2nd generation document database
Maybe something like this

metadata.Add("foo", new MetadataAsDictionary(new Dictionary<string, object> {{"test","test"}}));

But this throws a NotSupportedException

Oren Eini (Ayende Rahien)

unread,
Feb 25, 2018, 6:28:47 AM2/25/18
to ravendb
IIRC, Just a Dictionary<string,object> should work there.

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

marcus

unread,
Feb 25, 2018, 1:33:10 PM2/25/18
to RavenDB - 2nd generation document database
With this code I get the following exception:

var metadata = session.Advanced.GetMetadataFor(about);

metadata.Add("sub", new Dictionary<string, object> {{"foo","bar"}});



NotSupportedException: The value type System.Collections.Generic.KeyValuePair`2[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] of key sub is not supported in the metadata
Raven.Client.Json.BlittableJsonWriter.WritePropertyValue(string propName, object value) in C:\Builds\RavenDB-4.0-Nightly\src\Raven.Client\Json\BlittableJsonWriter.cs
Raven.Client.Json.BlittableJsonWriter.WritePropertyValue(string propName, object value) in C:\Builds\RavenDB-4.0-Nightly\src\Raven.Client\Json\BlittableJsonWriter.cs
Raven.Client.Json.BlittableJsonWriter.WriteMetadata() in C:\Builds\RavenDB-4.0-Nightly\src\Raven.Client\Json\BlittableJsonWriter.cs
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteObjectStart(JsonWriter writer, object value, JsonContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, object value, Type objectType)
Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, object value, Type objectType)
Raven.Client.Documents.Session.EntityToBlittable.ConvertEntityToBlittable(object entity, DocumentInfo documentInfo) in C:\Builds\RavenDB-4.0-Nightly\src\Raven.Client\Documents\Session\EntityToBlittable.cs
Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.PrepareForEntitiesPuts(SaveChangesData result) in C:\Builds\RavenDB-4.0-Nightly\src\Raven.Client\Documents\Session\InMemoryDocumentSessionOperations.cs
Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.PrepareForSaveChanges() in C:\Builds\RavenDB-4.0-Nightly\src\Raven.Client\Documents\Session\InMemoryDocumentSessionOperations.cs
Raven.Client.Documents.Session.Operations.BatchOperation.CreateRequest() in C:\Builds\RavenDB-4.0-Nightly\src\Raven.Client\Documents\Session\Operations\BatchOperation.cs
Raven.Client.Documents.Session.AsyncDocumentSession+<SaveChangesAsync>d__20.MoveNext() in C:\Builds\RavenDB-4.0-Nightly\src\Raven.Client\Documents\Session\AsyncDocumentSession.cs
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
src.Controllers.HomeController+<CreatePage>d__6.MoveNext() in HomeController.cs
+
                await session.SaveChangesAsync();


To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Feb 26, 2018, 3:11:52 AM2/26/18
to ravendb
Fixed and will be in the next nightly
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

marcus

unread,
Feb 26, 2018, 4:02:03 AM2/26/18
to RavenDB - 2nd generation document database
Thanks

marcus

unread,
Feb 27, 2018, 1:06:28 AM2/27/18
to RavenDB - 2nd generation document database
With the latest nightly RavenDB-4.0.3-nightly-20180227-0500-osx-x64 this issue still exists.

    [Fact]
    public void CanAddMetadata()
    {
      using (var documentStore = GetDocumentStore())
      {
        var document = new Document();

        using (var session = documentStore.OpenSession())
        {
          session.Store(document);
          var metadata = session.Advanced.GetMetadataFor(document);
          metadata.Add("test", new Dictionary<string, object> {{ "a", "b" }});
          session.SaveChanges();
        }

        using (var session = documentStore.OpenSession())
        {
          document = session.Load<Document>(document.Id);
          var metadata = session.Advanced.GetMetadataFor(document);

          Assert.Equal("b", metadata.GetObject("test").GetString("a"));
        }
        
      }
    }


System.NotSupportedException : The value type System.Collections.Generic.KeyValuePair`2[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] of key test is not supported in the metadata
      Stack Trace:
        C:\Builds\RavenDB-4.0-Nightly\src\Raven.Client\Json\BlittableJsonWriter.cs(217,0): at Raven.Client.Json.BlittableJsonWriter.WritePropertyValue(String propName, Object value)
        C:\Builds\RavenDB-4.0-Nightly\src\Raven.Client\Json\BlittableJsonWriter.cs(210,0): at Raven.Client.Json.BlittableJsonWriter.WritePropertyValue(String propName, Object value)
        C:\Builds\RavenDB-4.0-Nightly\src\Raven.Client\Json\BlittableJsonWriter.cs(45,0): at Raven.Client.Json.BlittableJsonWriter.WriteMetadata()
           at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteObjectStart(JsonWriter writer, Object value, JsonContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
           at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
           at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
           at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
        C:\Builds\RavenDB-4.0-Nightly\src\Raven.Client\Documents\Session\EntityToBlittable.cs(41,0): at Raven.Client.Documents.Session.EntityToBlittable.ConvertEntityToBlittable(Object entity, DocumentInfo documentInfo)
        C:\Builds\RavenDB-4.0-Nightly\src\Raven.Client\Documents\Session\InMemoryDocumentSessionOperations.cs(804,0): at Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.PrepareForEntitiesPuts(SaveChangesData result)
        C:\Builds\RavenDB-4.0-Nightly\src\Raven.Client\Documents\Session\InMemoryDocumentSessionOperations.cs(712,0): at Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.PrepareForSaveChanges()
        C:\Builds\RavenDB-4.0-Nightly\src\Raven.Client\Documents\Session\Operations\BatchOperation.cs(24,0): at Raven.Client.Documents.Session.Operations.BatchOperation.CreateRequest()
        C:\Builds\RavenDB-4.0-Nightly\src\Raven.Client\Documents\Session\DocumentSession.cs(71,0): at Raven.Client.Documents.Session.DocumentSession.SaveChanges()
        /Users/maqe/temp/FailingTests/PatchRequest/UnitTest1.cs(90,0): at PatchRequest.TestDriverExampleTest.CanAddMetadata()



Den måndag 26 februari 2018 kl. 09:11:52 UTC+1 skrev Oren Eini:

Arkadiusz Palinski

unread,
Feb 27, 2018, 7:06:16 AM2/27/18
to rav...@googlegroups.com
Did you update RavenDB client as well?

Arkadiusz Palinski

unread,
Feb 27, 2018, 7:08:54 AM2/27/18
to rav...@googlegroups.com
Also the test you provided is passing. I see you are running it on OSX, right?

marcus

unread,
Feb 27, 2018, 10:23:57 AM2/27/18
to RavenDB - 2nd generation document database
Sorry, my bad. I didn't use the correct version of RavenDB.TestDriver. The tests pass now
Reply all
Reply to author
Forward
0 new messages