MongoDB id remains null after InsertOneAsync -


i have base class entity has string id member , derived class a.

but when creating new instance of derived class , using insertoneasync add collection, document added database null id value.

using objectid id seem work, i'm trying prevent mongodb dependency in models.

i experimented following code, results same:

bsonclassmap.registerclassmap<entity>(cm => {     cm.mapidfield(x => x.id).setserializer(new stringserializer(bsontype.objectid)); }); 

i had same issue , got work (with 2.0 driver) these attributes:

[bsonid] [bsonrepresentation(bsontype.objectid)] [bsonignoreifdefault] 

or equivalent bsonclassmap fluent interface:

bsonclassmap.registerclassmap<entity>(cm => {       cm.mapidfield(x => x.id)       .setserializer(new stringserializer(bsontype.objectid))       .setignoreifdefault(true); }); 

i tried same working .replaceoneasync upsert on leaves id still null


Comments

Popular posts from this blog

java - Ebean enhancement ignores a model -

ubuntu - How to disable Kernel Module Signing in linux -

SQL php on different pages to Insert (mysqli) -