2016-12-16 46 views
1

我使用AspNetCore.Identity.MongoDB nuget package可以將一些Asp.Net標識特徵轉換爲my project使用Mongo C#驅動程序可以反序列化繼承對象

然後我想擴展MongoIdentityUser,它存在於我最初爲我的項目創建的用戶類型中,因此我嘗試從該類繼承並創建my User Class,它具有MongoIdentityUser作爲其基類。

如果我試圖查詢我的集合,我有一個MongoIdentityUser存儲,並嘗試將其反序列化到MongoIdentityUser我得到了一個項目,所以成功。

但是,如果我嘗試將其反序列化爲My User這是剛剛繼承的類的MongoDBUser我得到這個異常: Exception

是它無法像的程度,我想一個類?另外,例外是很沒用,不知道爲什麼它不給我更詳細的異常

JSON對象看起來像這樣

{ 
    "_id": "[email protected]", 
    "userName": "[email protected]", 
    "normalizedUserName": "[email protected]", 
    "email": { 
     "value": "[email protected]", 
     "confirmationRecord": null, 
     "normalizedValue": "[email protected]" 
    }, 
    "phoneNumber": null, 
    "passwordHash": "xxx", 
    "securityStamp": "87242bb7-2a09-4905-ba61", 
    "isTwoFactorEnabled": false, 
    "claims": [], 
    "logins": [], 
    "accessFailedCount": 0, 
    "isLockoutEnabled": true, 
    "lockoutEndDate": null, 
    "createdOn": { 
     "instant": { 
      "$date": "2016-11-13T17:05:59.487Z" 
     } 
    }, 
    "deletedOn": null 
} 
+0

恕我直言,最新發布的修正,你忘了使用類似'BsonClassMap.LookupClassMap(typeof(User))';)來註冊派生類。 –

+0

@ shA.t但不會只給我只有MongoIdentityUser屬性或用戶屬性,而不是兩個類屬性? – Mech0z

+0

這不是關於MongoDB基於它們可以序列化的類的屬性([this for more]](http://mongodb.github.io/mongo-csharp-driver/2.0/reference/bson/mapping/); )。 –

回答