public SetIdGeneratorConvention ( IIdGeneratorConvention convention ) : |
||
convention | IIdGeneratorConvention | An Id generator convention. |
리턴 |
public void AfterPropertiesSet() { var defaultProfile = ConventionProfile.GetDefault(); _profile = new ConventionProfile(); _filter = new ConventionFilterHelper(IncludeFilters, ExcludeFilters); _profile.SetDefaultValueConvention(DefaultValueConvention ?? defaultProfile.DefaultValueConvention); _profile.SetElementNameConvention(ElementNameConvention ?? defaultProfile.ElementNameConvention); _profile.SetExtraElementsMemberConvention(ExtraElementsMemberConvention ?? defaultProfile.ExtraElementsMemberConvention); _profile.SetIdGeneratorConvention(IdGeneratorConvention ?? defaultProfile.IdGeneratorConvention); _profile.SetIdMemberConvention(IdMemberConvention ?? defaultProfile.IdMemberConvention); _profile.SetIgnoreExtraElementsConvention(IgnoreExtraElementsConvention ?? defaultProfile.IgnoreExtraElementsConvention); _profile.SetIgnoreIfDefaultConvention(IgnoreIfDefaultConvention ?? defaultProfile.IgnoreIfDefaultConvention); _profile.SetIgnoreIfNullConvention(IgnoreIfNullConvention ?? defaultProfile.IgnoreIfNullConvention); _profile.SetMemberFinderConvention(MemberFinderConvention ?? defaultProfile.MemberFinderConvention); _profile.SetSerializationOptionsConvention(SerializationOptionsConvention ?? defaultProfile.SerializationOptionsConvention); BsonClassMap.RegisterConventions(_profile, _filter.Filter); }
/// <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); }