我是 MongoDB 的初学者。我在 Mongo 中有一个分层模型。请参阅下面我的代码。
public class Technology
{
public Technology()
{
ProductGroups = new List<ProductGroup>().ToArray();
}
[BsonRepresentation(BsonType.ObjectId)]
public ObjectId _id { get; set; }
public string Name { get; set; }
[BsonRepresentation(BsonType.Array)]
public ProductGroup[] ProductGroups { get; set; }
}
public class ProductGroup
{
public ProductGroup()
{
ProductTypes = new List<ProductType>().ToArray();
}
[BsonRepresentation(BsonType.ObjectId)]
public ObjectId _id { get; set; }
public string Name { get; set; }
[BsonRepresentation(BsonType.Array)]
public ProductType[] ProductTypes { get; set; }
}
public class ProductType
{
[BsonRepresentation(BsonType.ObjectId)]
public ObjectId _id { get; set; }
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我成功地将Technology数据完全插入到文档中。
public bool CreateTechnology(Technology model)
{
bool status = false;
try
{
if (!string.IsNullOrEmpty(model.Name))
{
Collection = DataBase.GetCollection<Product>(TECHNOLOGY);
BsonDocument product = new BsonDocument
{
{"Name", model.Name.Trim()},
{"ProductGroups", new BsonArray( new BsonValue []{})}
};
Collection.Insert(product);
status = true;
}
}
catch
{
status = false;
}
return status;
}
Run Code Online (Sandbox Code Playgroud)
请参阅 Robomongo 数据查看器。

一切正常,但是当我尝试选择要列出的数据时,它显示了一个错误,例如

模型中是否需要任何额外配置?
| 归档时间: |
|
| 查看次数: |
4776 次 |
| 最近记录: |