Programatic way to ignore a property when saving?

388 views
Skip to first unread message

Justin A

unread,
Apr 28, 2016, 2:10:28 AM4/28/16
to RavenDB - 2nd generation document database
Is there a way we can tell RavenDb to ignore a classes property without using [JsonIgnore] ?

The idea is that we're using a nuget package and we're saving a model/object that's defined in that package. As such, we can't change the class (it's in the nuget package) and no .. don't suggest fork/change, plz.

Is this possible?

can we define .. say at initialization time .. that the property `Name` on the class User should not be persisted to RavenDb (for example)?

ta!

:)

-J-

Matthias De Ridder

unread,
Apr 28, 2016, 4:02:44 AM4/28/16
to RavenDB - 2nd generation document database
I don't know if it is the best solution, but you could remove the property from the RavenJObject document in the AfterConversionToDocument method when you implement and add an IDocumentConversionListener.

Mario De Schaepmeester

unread,
Apr 28, 2016, 4:10:49 AM4/28/16
to RavenDB - 2nd generation document database
What I would do is to map the external library object to one that you have control over and persist the latter. Requires a bit more maintenance work but saving external entities is something I'd never do anyway. Might become nasty in your database and you won't find out soon.

Since you already have interest in selecting data that you want to save, this is most likely what you'd want to do in the long run anyway.

If that doesn't satisfy you, you could try experimenting with a custom JsonContractResolver, but if I understand it correctly it's not intended to determine how specific types are persisted (you might incur performance hits that way).

Oren Eini (Ayende Rahien)

unread,
Apr 28, 2016, 8:51:51 AM4/28/16
to ravendb
JsonContractResolver is the way to go, but I would strongly suggest that you'll go with Mario's suggestion of owning your entities.

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

Chris Marisic

unread,
Apr 28, 2016, 9:54:45 AM4/28/16
to RavenDB - 2nd generation document database
+2

Michael Yarichuk

unread,
Apr 28, 2016, 10:38:01 AM4/28/16
to RavenDB - 2nd generation document database
The entities mapping can be less painful with something like AutoMapper (https://github.com/AutoMapper/AutoMapper) -> it can shorten the amount of plumbing code needed to map between entities
--
Best regards,

 

Hibernating Rhinos Ltd  cid:image001.png@01CF95E2.8ED1B7D0

Michael Yarichuk l RavenDB Core Team 

RavenDB paving the way to "Data Made Simple"   http://ravendb.net/  

Chris Marisic

unread,
May 2, 2016, 9:42:35 AM5/2/16
to RavenDB - 2nd generation document database
Personally i've never found automapper actually helpful, i've found it be more work than just doing it by hand.
Reply all
Reply to author
Forward
0 new messages