可以我用mongodb的C#驾驶员
问题描述:
波苏斯我想知道如果我可以读取和写入原始波苏斯到的MongoDB可以我用mongodb的C#驾驶员
驾驶员教程显示在一个时间将每个字段以一个bsondocument一个。 Bsonserialzer做到了吗?
我可以自己写一些东西来反思一个对象,但我不知道它已经存在。
与动态expandos的工作将是很好
答
是的,10gen的官方C# MongoDB driver支持POCO系列化和deserialisation,例如
MongoCollection<Thing> thingCollection = _db.GetCollection<Thing>("things");
Thing thing = col.FindAllAs<Thing>();
col.Insert(new Thing { Name = "Foo" });
答
我觉得你可以,你应该,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);
});
tx - 它也做expandos吗? – pm100 2011-05-19 16:06:14
不,据我所知,尚未支持动态类型的序列化或反序列化。 – 2011-05-21 04:13:46
FindAll是否支持接口?即IThing thing = col.FindAllAs(); –
2011-06-12 18:30:29