C# MongoDb C驱动程序,类型为的属性未保存

C# MongoDb C驱动程序,类型为的属性未保存,c#,mongodb,mongodb-.net-driver,C#,Mongodb,Mongodb .net Driver,使用MongoDb站点的C驱动程序将我的web应用的持久层更改为MongoDb。我惊喜地发现我所有的考试都通过了。。。除了一节课。它的一个属性是一个实现IList的类型,由于某种原因,它不保存其项 我已经构建了一个最小的测试用例来说明。以下是创建和保存父对象的测试代码: var fooCollection = database.GetCollection<Foo>( typeof( Foo ).Name ); var foo = new Foo {Id = "Root"}; foo.

使用MongoDb站点的C驱动程序将我的web应用的持久层更改为MongoDb。我惊喜地发现我所有的考试都通过了。。。除了一节课。它的一个属性是一个实现IList的类型,由于某种原因,它不保存其项

我已经构建了一个最小的测试用例来说明。以下是创建和保存父对象的测试代码:

var fooCollection = database.GetCollection<Foo>( typeof( Foo ).Name );
var foo = new Foo {Id = "Root"};
foo.Foos.Add( new Foo{ Id = "Child" } );
fooCollection.Save( foo );
但我需要的是:

public class Foo {
  public Foo() {
    Foos = new FooList();
  }
  public FooList Foos;
  public string Id;
}

public class FooList : IList<Foo> {
   //IList implementation omitted for brevity
}
请注意,这与我的IList实现无关,因为如果我使用傻瓜列表,结果是相同的

我认为BSON序列化程序正在变得混乱?我查看了有关鉴别器的文档,这使我认为这可能会有所帮助:

BsonClassMap.RegisterClassMap<List<Foo>>( cm => {
  cm.AutoMap();
  cm.SetIsRootClass( true );
} );
BsonClassMap.RegisterClassMap<FooList>();    
我怎样才能正确地拯救傻瓜

我能复制你的样子 使用0.9进行描述,但它正在工作 正确使用最新代码

您可以自己构建驱动程序 来自github中的最新代码,或 等待0.11,它非常快就会到来 很快


-Robert Stam,在

上,您是否尝试添加任何BsonKnownType属性?您好。除非我弄错了,否则我上面列出的RegisterClassMap代码相当于使用BsonKnownType属性:对于任何对这个问题感兴趣的人,我们将在mongodb用户Google组中解决它。。。仍然没有运气,如果我找到解决办法,我会发回这里。
public class Foo {
  public Foo() {
    Foos = new FooList();
  }
  public FooList Foos;
  public string Id;
}

public class FooList : IList<Foo> {
   //IList implementation omitted for brevity
}
{ "_id" : "root", "Foos" : { "Capacity" : 4 } }
BsonClassMap.RegisterClassMap<List<Foo>>( cm => {
  cm.AutoMap();
  cm.SetIsRootClass( true );
} );
BsonClassMap.RegisterClassMap<FooList>();    
{ "_id" : "root", "Foos" : { "_t" : [ "List`1", "FooList" ], "Capacity" : 4 } }