我正在尝试使用 C# 驱动程序
(最新驱动程序版本 2.0.1.27)从 MongoDB
获取一些结果。
这就是我对 mongo 的称呼:
public static async Task < List < MomLogModel >> MomLogAr(MomLogArModel arama) {
var asd = Builders < MomLogModel > .Filter.Where(a => a.SipID == arama.SipID);
asd = asd & Builders < MomLogModel > .Filter.Where(a => a._id == arama._id);
var donucek = await mongoContex.MomLog.Find(asd).ToListAsync().ConfigureAwait(false);
}
这是 MomLogModel 类:
public class MomLogModel {
[BsonRepresentation(BsonType.ObjectId)]
public string _id {
get;
set;
}
[BsonElement("g")]
public BsonDocument gelen {
get;
set;
}
[BsonElement("t")]
public DateTime YaratTarih {
get {
return DateTime.Now;
}
set {
YaratilisTarih = value;
}
}
[BsonElement("m")]
public string MesajKod {
get;
set;
}
[BsonElement("re")]
public bool Rar {
get;
set;
}
[BsonElement("kz")]
public double KaZa {
get;
set;
}
[BsonElement("si")]
public int SipID {
get;
set;
}
}
当我运行它时,出现以下错误:
Method not found: 'Boolean MongoDB.Bson.Serialization.IBsonArraySerializer.TryGetItemSerializationInfo(MongoDB.Bson.Serialization.BsonSerializationInfo ByRef)'.
我已经尝试从模型中删除 BsonRepresentation
但它没有解决问题。
也尝试过更改它,但根本无法找出导致问题的原因。
最佳答案
看来,在我添加这个项目 dll 的项目中,我有 MongoDB.Bson 并且它的版本是旧版本。
因此,正如@CraigWilson 所建议的那样,有 2 个不同版本的引用导致了问题。
更新引用解决了问题。
关于c# - 未找到 MongoDB C# 驱动程序方法 MongoDB.Bson.Serialization.BsonSerializationInfo ByRef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31026622/