我在我的数据库中有一个“BSonElement”,我用标准查询重试它。BSonElement to c#数据类型
问题是我无法将BsonDocument转换为类型。
实施例:
UPDATE 1:
public partial class item_Stat
{
[BsonExtraElements]
public BsonDocument all_stat;
}
基本上,我有进入我DB 10-15属性(字段),我可以用 “BsonExtraElements” 读取。通过这种方式,我可以重试属性,而无需在C#中定义它 。
all_stat,可以有10-15-20的性质改变。 C#是键入语言,所以我不能在C#中定义这个属性,并且我使用了ExtraElements。
问题是,当我从数据库查询对象。
var item_db = myMongoCollection.find(theQuery); // find the OBJECT
item_db.all_stat // all the property hare HERE
// find the property "category_01"
var i = item_db.all_stat.Where(p => p.Name == "category_01").Single();
// ok, i have found the Category, so i can cast it to C# Data Type
var typed_value = (ItemStatSingle) i.Value // BsonElement to ItemStatSingle
不是wath我想要 – Dada 2012-02-24 21:29:19
我已更新问题 – Dada 2012-02-25 10:18:17