0
我有如下DB結構。默認ID在MongoDb中生成00000
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; }
}
正如你所看到的,一所大學可以有多所大學。 我添加的數據是遵循
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;
它是正確生成ID爲大學,但對每一個大學,它的產生000000
我要生成一個不同的默認ID爲每個學院。