这一行失败并显示一条消息:不支持的过滤器:(序列化(cnt)==序列化(cnt))???。
如果我删除&& x.cnt == x.cnt它工作正常。 我是否必须定义自定义甚至告诉代码标准序列化在类上是什么。 如果我不执行上述操作,则保存正常并读取x.cnt == 4
var tests = await db.GetCollection<ctest>("ctests").Find(x => x.cnt == 4 && x.cnt == x.cnt).ToListAsync();
using System;
using System.Linq;
using System.Windows.Forms;
namespace MongoDBTest
{
public partial class Form1 : Form
{
private async void btnConsultantTest_Click(object sender, EventArgs e)
{
IMongoDatabase db = PreLoad.MongoDB;
var ctestCollection = db.GetCollection<ctest>("ctests");
var entity = new ctest { cnt = 4, id = 77};
await ctestCollection.InsertOneAsync(entity);
var tests = await db.GetCollection<ctest>("ctests").Find(x => x.cnt == 4 && x.cnt == x.cnt).ToListAsync();
ctest ctester = tests.FirstOrDefault<ctest>();
}
}
}
using MongoDB.Bson.Serialization.Attributes;
namespace MongoDBTest
{
public class ctest
{
[BsonId]
public int id { get; set; }
public int anint { get; set; }
public int cnt { get; set; }
}
}