Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用带谓词的Linq.Any()从C#-查询MongoDb_C#_Linq_Mongodb_Mongodb .net Driver - Fatal编程技术网

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

使用带谓词的Linq.Any()从C#-查询MongoDb,c#,linq,mongodb,mongodb-.net-driver,C#,Linq,Mongodb,Mongodb .net Driver,我正试图使用c#驱动程序查询一个集合。文件结构为: { "_id" : 3121 , "Active" : true , "CategoryId" : 1 , "Crci" : "IH" , "CultureId" : null , "DateUpdated" : { "$date" : 1381916923120 } , "Description" : "National Careers

我正试图使用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=637
cultureId=1
,我得到错误:
“Unsupported where子句:((Int32)ccer.careerId==637)”

但是,在MongoDb教程页面上,它说这类查询包括:


我目前使用的是1.8.3版的驱动程序,使用的是
where
,并且在使用Linq时,使用的条件子句仅限于.NET数据类型的一个子集。使用
Int32
/(
int
)代替
short

数据类型是否匹配?
request
上的
CareerId
是Int32吗?使用Query类来构建如下查询:Query.EQ(“CareerId”,request.CareerId)。@wiredparie这是一个有趣的事情,
CareerId
是一个简短的名称,“CareerCultureExternalResource
的数据类型也是如此。因此,数据类型匹配,但错误没有意义。我不知道为什么它试图将其转换为
int`@bradciven,我宁愿继续使用linq而不是查询生成器,除非有特殊情况。我们选择mongo的原因之一是它出色的Linq支持。您可以尝试使用
int
?通过快速阅读周围的几个点,听起来并不是所有的数据类型都在
where
中得到同等的支持。