2011-05-19 61 views
3

波蘇斯我想知道如果我可以讀取和寫入原始波蘇斯到的MongoDB可以我用mongodb的C#駕駛員

駕駛員教程顯示在一個時間將每個字段以一個bsondocument一個。 Bsonserialzer做到了嗎?

我可以自己寫一些東西來反思一個對象,但我不知道它已經存在。

與動態expandos的工作將是很好

回答

3

是的,10gen的官方C# MongoDB driver支持POCO系列化和deserialisation,例如

MongoCollection<Thing> thingCollection = _db.GetCollection<Thing>("things"); 
Thing thing = col.FindAllAs<Thing>(); 
col.Insert(new Thing { Name = "Foo" }); 
+0

tx - 它也做expandos嗎? – pm100 2011-05-19 16:06:14

+0

不,據我所知,尚未支持動態類型的序列化或反序列化。 – 2011-05-21 04:13:46

+0

FindAll是否支持接口?即IThing thing = col.FindAllAs (); – 2011-06-12 18:30:29

2

我覺得你可以,你應該,10gen驅動POCO對象。您可以在沒有任何引用Mongo.Driver或Mongo.BSon的情況下設計您的POCO模型,並配置您的應用程序的入口點以使用該程序集,設置索引,ingnore字段,鑑別器,ID列和大等

BsonClassMap.RegisterClassMap<Post>(cm => 
     { 
      cm.AutoMap(); 
      cm.SetIdMember(cm.GetMemberMap(c => c.IdPost)); 
      cm.UnmapProperty(c => c.TimeStamp); 
      cm.UnmapProperty(c => c.DatePostedFormat); 
      cm.UnmapProperty(c => c.IdPostString); 
      cm.UnmapProperty(c => c.ForumAvatar); 
      cm.UnmapProperty(c => c.ForumAvatarAlt); 
     });