c# - Default Id generating 00000 in MongoDb -
i have db structure follow .
public class university { [bsonid] public objectid id { get; set; } public string name { get; set; } public string code { get; set; } public ilist<college> colleges { get; set; } } public class college { [bsonid] public objectid id { get; set; } public string name { get; set; } public string code { get; set; } }
as can see, university can have multiple colleges . i'm adding data follow
ilist<college> lstcolleges=new list<college>(); college clg1=new college(){ name="clg1", code="clg1001" }; college clg2=new college(){ name="clg2", code="clg1002" }; lstcolleges.add(clg1); lstcolleges.add(clg2); university unv=new university(){ name="univ", code="un101", colleges=lstcolleges }; var collections = mongodatabase.getcollection<university>("university"); collections.insert(unv); var id = student.unv;
it correctly generating id university, every college, it's generating 000000.
i want generate different default id each colleges.
only top level _id
automatically assigned.
in embedded document need manually generated.
you in ctor:
public class college { public college { id = objectid.generatenewid(); } [bsonid] public objectid id { get; set; } public string name { get; set; } public string code { get; set; } }
Comments
Post a Comment