From 2e31c312856a69b6fa7c486b871565afb3ea8905 Mon Sep 17 00:00:00 2001 From: Argo-MacBookPro Date: Tue, 30 Oct 2018 15:37:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9BUG=EF=BC=9A=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E7=B1=BB=E5=9E=8B=E5=8F=98=E5=8C=96=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=95=B0=E6=8D=AE=E5=BA=93=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs b/Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs index b935f080..1dd30068 100644 --- a/Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs +++ b/Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs @@ -28,9 +28,10 @@ namespace Bootstrap.DataAccess.MongoDB if (!_register) { _register = true; - DbAdapterManager.RegisterConfigChangeCallback(InitDb); + DbAdapterManager.RegisterConfigChangeCallback("MongoDB", InitDb); } InitDb(); + InitClassMap(); } return _db; } @@ -42,11 +43,15 @@ namespace Bootstrap.DataAccess.MongoDB if (string.IsNullOrEmpty(connectString)) throw new InvalidOperationException("Please set the BA default value in configuration file."); var seq = connectString.Split(";", StringSplitOptions.RemoveEmptyEntries); - if (seq.Length != 2) throw new InvalidOperationException(""); + if (seq.Length != 2) return; + var client = new MongoClient(seq[0]); _db = client.GetDatabase(seq[1].Split("=", StringSplitOptions.RemoveEmptyEntries).LastOrDefault()); + } - BsonSerializer.RegisterSerializer(new DateTimeSerializer(DateTimeKind.Local)); + private static void InitClassMap() + { + BsonSerializer.RegisterSerializer(DateTimeSerializer.LocalInstance); if (!BsonClassMap.IsClassMapRegistered(typeof(BootstrapDict))) { BsonClassMap.RegisterClassMap(md =>