我在我的數據庫中有一個「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