当我们尝试在MongoDB中使用linq contains查询时,会报错
Unsupported filter contains in linq. How to use contains and ToLower in linq query? [duplicate]
解决方式是使用In
public async Task<List<T>> GetByLine(List<double> linno, DateTime startTime, DateTime endTime)
{
//and表示符合两个条件
var testfilter = Builders<T>.Filter.And(Builders<T>.Filter.In("lno", linno), Builders<T>.Filter.Where(x => x.InsertTime >= startTime && x.InsertTime <= endTime));
var filter = Builders<T>.Filter.In("lno", linno);
return await _collection.Find<T>(testfilter).ToListAsync();
//下面这种会报错
//return await _collection.Find<T>(T => linno.Contains(T.lno.Value) && T.InsertTime >= startTime && T.InsertTime <= endTime).ToListAsync();
}