/// <summary> /// Registers the MongoDB Bson serialization conventions. /// </summary> /// <param name="autoGenerateID">A <see cref="Boolean"/> value which indicates whether /// the ID value should be automatically generated when a new document is inserting.</param> /// <param name="localDateTime">A <see cref="Boolean"/> value which indicates whether /// the local date/time should be used when serializing/deserializing <see cref="DateTime"/> values.</param> /// <param name="additionConventions">Additional conventions that needs to be registered.</param> public static void RegisterConventions(bool autoGenerateID, bool localDateTime, ConventionProfile additionConventions) { var convention = new ConventionProfile(); convention.SetIdMemberConvention(new NamedIdMemberConvention("id", "Id", "ID", "iD")); if (autoGenerateID) convention.SetIdGeneratorConvention(new GuidIDGeneratorConvention()); if (localDateTime) convention.SetSerializationOptionsConvention(new UseLocalDateTimeConvention()); if (additionConventions != null) convention.Merge(additionConventions); BsonClassMap.RegisterConventions(convention, type => true); }