我想查询MongoDB以获得Top 5000记录,这会导致以下错误。 我正在使用C#LINQ驱动程序,而TermMonitorIds是BsonArray。Linq查询其中包含列表中的列表
{ “无法确定表达式的序列信息:)x.ToString(”}
public IList<SocialRecord> GetManyBetweenDatesLimited(List<string> termMonitorIds, string[] sources, DateTime fr, DateTime to)
{
IList<SocialRecord> entities = new List<SocialRecord>();
try
{
entities =
(from e in this.collection.AsQueryable<SocialRecord>()
where (e.TermMonitorIds.Any(x => termMonitorIds.Contains(x.ToString()))) && (sources.Contains(e.SocialType))
&& (e.DateCreated.Date >= fr.Date) && (e.DateCreated.Date <= to.Date)
select e)
.Take(5000)
.ToList();
}
catch (Exception ex)
{
Log.Error("Error Message", ex);
}
return entities;
}
我试图改变列表以BsonArray象下面这样:
BsonArray bArray = new BsonArray();
foreach (var term in termMonitorIds)
{
bArray.Add(term.ToBson());
}
静止最后带上如下错误消息:
'/'应用程序中的服务器错误。
无法将字符串值写入BSON文档的根级别。
描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关该错误的更多信息以及源代码的位置。
异常详细信息:System.InvalidOperationException:String值无法写入到BSON文档的根级别。
您使用的是什么版本的MongoDB? – sloth
MongoDb 2.4.9版本 –