SiberianGuy
SiberianGuy

Reputation: 25282

RavenDb objects instantiation

I have noticed RavenDb doesn't require entities to have default constructor. How does it create objects during queries then?

Upvotes: 2

Views: 531

Answers (3)

Ayende Rahien
Ayende Rahien

Reputation: 22956

Idsa, The way it works, when you have a ctor and a json, we try to match the ctor parameters to the json properties and see if we can make it work.

This behavior is built into Json.NET

Upvotes: 2

Peter
Peter

Reputation: 14098

I believe RavenDB can't handle this automatically. RavenDB serializes to JSON using the Newtonsoft JSON library, if I'm not mistaken. Thus, you have to provide it a custom resolver.

See 'Immutable entities' on the RavenDB FAQ, and this discussion on the Raven DB Google Group for some more info.

Upvotes: 0

Jonathan
Jonathan

Reputation: 2358

When you dont specify one Visual Studio automatically generates one in the IL.

If you specified a private no arguments constructor the default public no arguments constructor would not be generated.

As an experiment try adding a default no arguments private constructor to test this theory. I would assume RavenDb might have an issue with this.

Upvotes: -1

Related Questions