SetIdMemberConvention() public method

Sets the Id member convention.
public SetIdMemberConvention ( IIdMemberConvention convention ) : ConventionProfile
convention IIdMemberConvention An Id member convention.
return ConventionProfile
 public static void ConfigureMapping()
 {
     var conventionsProfile = new ConventionProfile();
     conventionsProfile.SetIgnoreExtraElementsConvention(new AlwaysIgnoreExtraElementsConvention());
     conventionsProfile.SetIdMemberConvention(new NamedIdMemberConvention("Id"));
     BsonClassMap.RegisterConventions(conventionsProfile, t => typeof(ISagaEntity).IsAssignableFrom(t));
 }
        private IQueryable GetQueryableCollection(string connectionString, Dictionary<string, Type> providerTypes, string collectionName)
        {
            var collectionType = CreateDynamicTypeForCollection(collectionName, providerTypes);

            var conventions = new ConventionProfile();
            conventions.SetIdMemberConvention(new NamedIdMemberConvention(MongoMetadata.MappedObjectIdName));
            conventions.SetIgnoreExtraElementsConvention(new AlwaysIgnoreExtraElementsConvention());
            BsonClassMap.RegisterConventions(conventions, t => t == collectionType);

            return InterceptingProvider.Intercept(
                new MongoQueryableResource(connectionString, collectionName, collectionType),
                new ResultExpressionVisitor());
        }
 public LogEntryMongoDataService()
 {
     lock (this)
     {
         if (!BsonClassMap.IsClassMapRegistered(typeof(LogEntry)))
         {
             var noIdConventions = new ConventionProfile();
             noIdConventions.SetIdMemberConvention(new NamedIdMemberConvention()); // no names
             BsonClassMap.RegisterConventions(noIdConventions, t => t == typeof(LogEntry));
             BsonClassMap.RegisterClassMap<LogEntry>(cm => cm.AutoMap());
         }
     }
 }
Beispiel #4
0
        public static void ConfigureMongoDB(IUnityContainer container)
        {
            var settings = container.Resolve<PrototypeSettings>();
            container.RegisterInstance(new MongoViewDatabase(settings.MongoViewConnectionString).EnsureIndexes());
            container.RegisterInstance(new MongoLogsDatabase(settings.MongoLogsConnectionString).EnsureIndexes());
            container.RegisterInstance(new MongoEventsDatabase(settings.MongoEventsConnectionString));

            // Register bson serializer conventions
            var myConventions = new ConventionProfile();
            myConventions.SetIdMemberConvention(new NoDefaultPropertyIdConvention());
            myConventions.SetIgnoreExtraElementsConvention(new AlwaysIgnoreExtraElementsConvention());
            BsonClassMap.RegisterConventions(myConventions, type => true);
            DateTimeSerializationOptions.Defaults = DateTimeSerializationOptions.UtcInstance;
        }
        /// <summary>
        /// Initializes the <see cref="JobStore"/> class.
        /// </summary>
        static JobStore()
        {
            var myConventions = new ConventionProfile();
            myConventions.SetIdMemberConvention(new IdOrKeyConvention());
            BsonClassMap.RegisterConventions(
                myConventions,
                t => true
            );

            BsonSerializer.RegisterSerializer(
                typeof(JobKey),
                new JobKeySerializer()
            );

            BsonSerializer.RegisterSerializer(
                typeof(TriggerKey),
                new TriggerKeySerializer()
            );

            BsonSerializer.RegisterSerializer(
                typeof(JobDetailImpl),
                new JobDetailImplSerializer()
            );

            BsonClassMap.RegisterClassMap<JobDetailImpl>(cm =>
            {
                cm.AutoMap();
                cm.SetDiscriminator("JobDetailImpl");
            });

            BsonSerializer.RegisterSerializer(
                typeof(JobDataMap),
                new JobDataMapSerializer()
            );

            BsonSerializer.RegisterSerializer(
                typeof(DateTimeOffset),
                new DateTimeOffsetSerializer()
            );

            BsonSerializer.RegisterGenericSerializerDefinition(typeof(Collection.ISet<>), typeof(SetSerializer<>));

            BsonClassMap.RegisterClassMap<AbstractTrigger>(cm =>
            {
                cm.AutoMap();
                cm.SetIsRootClass(true);
            });

            BsonClassMap.RegisterClassMap<CalendarIntervalTriggerImpl>(cm =>
            {
                cm.AutoMap();
                cm.MapField("complete");
                cm.MapField("nextFireTimeUtc");
                cm.MapField("previousFireTimeUtc");
                cm.SetIgnoreExtraElements(true);
            });

            BsonClassMap.RegisterClassMap<CronTriggerImpl>(cm =>
            {
                cm.AutoMap();
                cm.MapField("nextFireTimeUtc");
                cm.MapField("previousFireTimeUtc");
                cm.MapField(x => x.TimeZone).SetSerializer(new TimeZoneInfoSerializer());
                cm.SetIgnoreExtraElements(true);
            });

            BsonSerializer.RegisterSerializer(typeof(TimeOfDay), new TimeOfDaySerializer());

            BsonClassMap.RegisterClassMap<DailyTimeIntervalTriggerImpl>(cm =>
            {
                cm.AutoMap();
                cm.MapField("complete");
                cm.MapField("nextFireTimeUtc");
                cm.MapField("previousFireTimeUtc");
                cm.MapField(x => x.TimeZone).SetSerializer(new TimeZoneInfoSerializer());
                cm.SetIgnoreExtraElements(true);
            });

            BsonClassMap.RegisterClassMap<SimpleTriggerImpl>(cm =>
            {
                cm.AutoMap();
                cm.MapField("complete");
                cm.MapField("nextFireTimeUtc");
                cm.MapField("previousFireTimeUtc");
                cm.SetIgnoreExtraElements(true);
            });
        }
        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);
        }