mongodb - Binary is not a valid representation for an ObjectIdSerializer -


i'm trying set objectid testobject class. problem keep getting exceptions , have no way of debugging serialization process.

my mongodb:

{     "_id" : luuid("964c87a0-bf8a-1f4e-be85-7aadb5315adb") } 

an error has occurred while resolving 'mongodatasource' data source: error occurred while invaking data retrieval method.

--- innerexception ---

an error occurred while deserializing object property of class testobject: cannot deserialize 'objectid' bsontype 'binary'.

--- innerexception ---

cannot deserialize 'objectid' bsontype 'binary'.

[dataobject] public class testobject {     [bsonid]     [bsonelement("_id")]     public objectid objectid { get; set; } } 

if make bsontype.binary

an error has occurred while resolving 'mongodatasource' data source: error occurred while invaking data retrieval method.

--- innerexception ---

exception has been thrown target of invocation.

--- innerexception ---

binary not valid representation objectidserializer.

[dataobject] public class testobject {     [bsonid]     [bsonelement("_id")]     [bsonrepresentation(bsontype.binary)]     public objectid objectid { get; set; } } 

the problem field inside mongo collection stored luuid (it's guid) different type compared objectid.

in mapping class, defined

[dataobject] public class testobject {     [bsonid]     [bsonelement("_id")]     public objectid objectid { get; set; } } 

and when driver tries deserialize value 964c87a0-bf8a-1f4e-be85-7aadb5315adb (string representation of guid) fails.

good news id generator guid ships drivers , can achieve desired result following driver's conventions:

public class testobject {     public guid id { get; set; } // note property renamed in id } 

as per official documentation can omit [bsonid] [bsonelement("_id")] , [bsonid(idgenerator = typeof(guidgenerator))] attributes long property named id , type 1 of supported ones.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -