3

I have a collection I am trying to query using the c# driver. the document structure is:

{ 
    "_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
}

the query I am trying to run is:

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

passing the values careerId = 637 and cultureId = 1, I get the error: "Unsupported where clause: ((Int32)ccer.CareerId == 637)"

However on the MongoDb tutorials page it says this kind of query is covered: http://docs.mongodb.org/ecosystem/tutorial/use-linq-queries-with-csharp-driver/

I am using version 1.8.3 of the driver

6
  • 2
    Are the data types matching? Is CareerId on request an Int32? Commented Jan 28, 2014 at 18:16
  • Use Query class to build your queries like this: Query.EQ("CareerId", request.CareerId). Commented Jan 29, 2014 at 4:41
  • @WiredPrairie That's one of the interesting things - the CareerId is a short and so is the data type for the 'CareerCultureExternalResource. So the data types match but the error doesn't make sense. I'm not sure why it is trying to cast it to an int` Commented Jan 29, 2014 at 9:11
  • @bradciven I'd rather keep to using linq rather than the query builder except for exceptional circumstances. One of the reasons we chose mongo was its excellent Linq support Commented Jan 29, 2014 at 9:15
  • Can you try with an int? From a quick read of a few spots around, it sounds like not all data types are supported equally in the where. Commented Jan 29, 2014 at 11:36

1 Answer 1

1

Currently, using where and a conditional clause like you've done, when using Linq, is limited to a subset of .NET data types. Instead of using a short, use a Int32/(int) instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.