ORM vs Direct in .NET

32 views
Skip to first unread message

Micah Hoover

unread,
Jan 4, 2017, 11:42:29 AM1/4/17
to mongodb-dev
Can anyone comment on the performance of the Mongo C# driver compared to sending JavaScript to the mongod?

In other databases there are ... colorful ... discussions about performance costs of the ORMs, but it looks like most .NET devs have just embraced the C# driver.

Or perhaps the C# driver supports low level access, and -if it does- how much difference does that make in terms of performance?


Robert Stam

unread,
Jan 4, 2017, 12:49:53 PM1/4/17
to mongo...@googlegroups.com
There's really no such thing as sending "JavaScript" to mongod from the .NET driver.

Your choice is between:

1. Using the general purpose BsonDocument object model (similar to JSON)
2. Using C# classes and serializing them to BSON

Serialization is handled by a serializer. The driver has a general purpose serialization mechanism based on "class maps". A class map controls how a C# class is mapped to and from BSON. There is a BsonClassMapSerializer that serializes data based on what the class map tells it to do.

Alternatively you could write your own custom serializer that should outperform the BsonClassMapSerializer, but probably by not that much.

My guess is that the following are in increasing order of performance:

1. BsonClassMapSerializer
2. Using the BsonDocument object model
3. Using a custom serializer for each C# class

But the difference between 1 and 3 is probably no more than 30% (IIRC from tests I did a long time ago), which is why most people just use the built in class map based serializers.


--
You received this message because you are subscribed to the Google Groups "mongodb-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-dev+unsubscribe@googlegroups.com.
To post to this group, send email to mongo...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-dev/d9d21e53-88f6-4ab8-a319-e67223c88df9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages