所有
在MongoDB数据库中插入后,我无法将“MongoDB.Bson.ObjectId”类型的对象转换为“MongoDB.Bson.BsonValue”
session.createNativeQuery()
如何在Unable之间轻松地强制转换'MongoDB.Bson.ObjectId'类型的对象来输入'MongoDB.Bson.BsonValue'?
答案 0 :(得分:0)
抱歉,误报。这是一个愚蠢的编程错误 在我的查询中检查是否插入了条目,我没有进行演员。
这是正确的代码:
ELLCsInterfaceLogEvent aLogEvent = null;
try
{
//BsonValue bval = MongoDB.Bson.BsonValue((ObjectId)UmbrellaLogId);
//new MongoDB.Bson.BsonValue((ObjectId)UmbrellaLogId);
MongoDB.Bson.ObjectId UmbrellaLogIdAsObjectId = (ObjectId)UmbrellaLogId;
BsonDocument logEventBsonDoc = new BsonDocument {
{"UmbrellaLogId",(BsonValue)UmbrellaLogIdAsObjectId}
}; // end of new BsonDocument
objUtility = new Utility();
objUtility.Insert(logEventBsonDoc, "FMS_TM_MST_LogEvents");
string[] arrFields = { "UmbrellaLogId" };
IMongoQuery query = Query.EQ("UmbrellaLogId", (BsonValue)UmbrellaLogIdAsObjectId);
aLogEvent = DBConnection.database.GetCollection<ELLCsLogEvent>("FMS_TM_MST_LogEvents")
.Find(query).SetFields(arrFields).ToList<ELLCsInterfaceLogEvent>().FirstOrDefault();
}
catch (Exception ex)
{
string something = ex.Message;
}
return aLogEvent;