gpt4 book ai didi

c# - 从 C# 查询 MongoDb - 使用带有谓词的 Linq .Any()

转载 作者:可可西里 更新时间:2023-11-01 10:43:55 26 4
gpt4 key购买 nike

我有一个正在尝试使用 C# 驱动程序查询的集合。文档结构是:

{ 
"_id" : 3121 ,
"Active" : true ,
"CategoryId" : 1 ,
"Crci" : "IH" ,
"CultureId" : null ,
"DateUpdated" : {
"$date" : 1381916923120
} ,
"Description" : "National Careers Service: Actuary" ,
"Keywords" : "" ,
"MaxLevel" : null ,
"MinLevel" : null ,
"PhoneNumber" : " " ,
"Priority" : 1 ,
"Title" : "National Careers Service: Actuary" ,
"WebUrl" : "https://nationalcareersservice.direct.gov.uk/advice/planning/jobprofiles/Pages/actuary.aspx" ,
"CareerCultureExternalResources" : [
{
"CareerId" : 5 ,
"CultureId" : 1 ,
"DisplayOrder" : 1 ,
"ExternalResourceId" : 3121 ,
"Vgs" : null
}
] ,
"SubjectExternalResources" : [ ] ,
"LifestyleCategories" : null
}

我尝试运行的查询是:

collection.AsQueryble().Where(
er =>
er.CareerCultureExternalResources.Any(
ccer => ccer.CareerId == request.CareerId && ccer.CultureId == request.CultureId));

传递值 careerId = 637cultureId = 1,我收到错误:"Unsupported where clause: ((Int32)ccer.CareerId == 637)”

但是在 MongoDb 教程页面上它说涵盖了这种查询: http://docs.mongodb.org/ecosystem/tutorial/use-linq-queries-with-csharp-driver/

我使用的是1.8.3版本的驱动

最佳答案

目前,在使用 Linq 时,使用 where 和条件子句仅限于 .NET 数据类型的子集。不要使用 short,而是使用 Int32/(int)。

关于c# - 从 C# 查询 MongoDb - 使用带有谓词的 Linq .Any(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21411918/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com