MongoDB从bson返回ToList

时间:2014-03-14 12:49:49

标签: linq mongodb mongodb-.net-driver bson

在下面的代码中,我正在查询我的数据库以查找specificik _id,该部分工作正常。现在的问题是我需要以某种方式在wpf数据网格中返回结果。我通常使用List<>和词典<>对于这种事情,但这在这里不起作用。

public List<MongoDBModel> MongoDBMeterInfo()
        {
            var connectionString = "mongodb://localhost";
            var mongoClient = new MongoClient(connectionString);
            var mongoServer = mongoClient.GetServer();
            var databaseName = "PointToPoint";
            var db = mongoServer.GetDatabase(databaseName);
            var mongodb = db.GetCollection<MongoDBModel>("OCS.MeterEntity");
            var mongodbQuery = Query<MongoDBModel>.EQ(x => x._id, CurrentMeter.MeterUID);
            var found = mongodb.FindOne(mongodbQuery);
        } 

[BsonIgnoreExtraElements]
    public class MongoDBModel
    {
        [BsonElement("_id")]
        public string _id { get; set; }
        [BsonElement("EncryptionKey")]
        public string EncryptionKey {get; set;}
        [BsonElement("DataTemplateKey")]
        public string DataTemplateKey { get; set; }
        [BsonElement("LoggerReadsPerDay")]
        public Int64 LoggerReadsPerDay { get; set; }
        [BsonElement("ListType")]
        public int ListType { get; set; }
        [BsonElement("IpAddress")]
        public string IpAddress { get; set; }
        [BsonElement("ReadMode")]
        public Boolean ReadMode { get; set; }
        [BsonElement("DefaultStartTimeStampUtc")]
        public string DefaultStartTimeStampUtc { get; set; }
        [BsonElement("LastSetTime")]
        public DateTime LastSetTime { get; set; }
        [BsonElement("LastReadGSMdata")]
        public DateTime LastReadGSMdata { get; set; }
        [BsonElement("DialBackPort")]
        public int DialBackPort { get; set; }
        [BsonElement("CID")]
        public int CID { get; set; }
        [BsonElement("ActiveFirmwareUpgrade")]
        public string ActiveFirmwareUpgrade { get; set; }
        [BsonElement("QueuedFirmwareUpgrade")]
        public string QueuedFirmwareUpgrade { get; set; }
        [BsonElement("DeviceAcceptedFirmwareActivationMessageOnLastConnect")]
        public Boolean DeviceAcceptedFirmwareActivationMessageOnLastConnect { get; set; }
        [BsonElement("WasConnectionLostLastTime")]
        public Boolean WasConnectionLostLastTime { get; set; }
    }

我需要做些什么才能让它发挥作用? :)

0 个答案:

没有答案