簡體   English   中英

從C#查詢MongoDb-使用帶有謂詞的Linq .Any()

[英]Query MongoDb from C# - using Linq .Any() with predicate

我有一個集合,我正在嘗試使用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 )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM