Is there a replacement for RavenJObject.FromObject in 4.x?

52 views
Skip to first unread message

Sean Buchanan

unread,
Jun 15, 2018, 11:16:55 AM6/15/18
to RavenDB - 2nd generation document database
In 3.x I was using the following code to insert new data to the database in batches:

                    RavenJObject metadata = new RavenJObject();
                    metadata.Add("Raven-Entity-Name", new RavenJValue(entityName));
                    PutCommandData putCommandData = new PutCommandData()
                    {
                        Metadata = metadata,
                        Key = documentId,
                        Document = RavenJObject.FromObject(aggregateRoot)
                    };

                    session.Advanced.Defer(putCommandData);


In the 4.x example (below), JSON values are added by hand. Is there some equivalent of RavenJObject.FromObject that can be used to create the JSON values so I don't have to write my own code for it?

session
    .Advanced
    .Defer(
        new PutCommandData("products/999-A", null, new DynamicJsonValue
        {
            ["Name"] = "My Product",
            ["Supplier"] = "suppliers/999-A",
            ["@metadata"] = new DynamicJsonValue
            {
                ["@collection"] = "Users"
            }
        }),

Oren Eini (Ayende Rahien)

unread,
Jun 15, 2018, 6:07:08 PM6/15/18
to ravendb
session
    .Advanced
    .Defer(
        new PutCommandDataWithBlittableJson("products/999-A", null, 
     ((DocumentSession)session).EntityToBlittable.ConvertEntityToBlittable(entity, null) ),



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.

Sean Buchanan

unread,
Jun 18, 2018, 9:53:08 AM6/18/18
to RavenDB - 2nd generation document database
PutCommandDataWithBlittableJson looks to be an internal class. (I'm using v4.0.5.) Was the intent to use reflection to create an instance of this?
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Jun 18, 2018, 9:04:30 PM6/18/18
to ravendb
No, the entire class is just:

 internal class PutCommandDataWithBlittableJson : PutCommandDataBase<BlittableJsonReaderObject>
 {
     public PutCommandDataWithBlittableJson(string id, string changeVector, BlittableJsonReaderObject document)
         : base(id, changeVector, document)
     {
     }
 }


You can use that directly ( PutCommandDataBase is public)
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Sean Buchanan

unread,
Jun 19, 2018, 10:11:45 AM6/19/18
to RavenDB - 2nd generation document database
Gotcha. Thanks a million.
Reply all
Reply to author
Forward
0 new messages