예제 #1
0
        public MongoDbContextModel Build()
        {
            lock (SyncObj) {
                var entityModels = _entityModelBuilders
                                   .Select(x => x.Value)
                                   .Cast <IMongoEntityModel> ()
                                   .ToImmutableDictionary(x => x.EntityType, x => x);

                var baseClasses = new List <Type> ();

                foreach (var entityModel in entityModels.Values)
                {
                    var map = entityModel.As <IHasBsonClassMap> ().GetMap();
                    if (!BsonClassMap.IsClassMapRegistered(map.ClassType))
                    {
                        BsonClassMap.RegisterClassMap(map);
                    }

                    baseClasses.AddRange(entityModel.EntityType.GetBaseClasses(includeObject: false));
                }

                baseClasses = baseClasses.Distinct().ToList();

                foreach (var baseClass in baseClasses)
                {
                    if (!BsonClassMap.IsClassMapRegistered(baseClass))
                    {
                        var map = new BsonClassMap(baseClass);
                        map.ConfigureRocketConventions();
                        BsonClassMap.RegisterClassMap(map);
                    }
                }

                return(new MongoDbContextModel(entityModels));
            }
        }
예제 #2
0
 public MongoEntityModelBuilder()
 {
     EntityType    = typeof(TEntity);
     _bsonClassMap = new BsonClassMap <TEntity> ();
     _bsonClassMap.ConfigureRocketConventions();
 }