Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Method 'Cast' is not supported" when Filtering Parent Documents by Child's GUID in Cosmos DB #976

Open
cloudsere opened this issue May 6, 2024 · 0 comments

Comments

@cloudsere
Copy link

cloudsere commented May 6, 2024

Describe the bug
I'm encountering an issue while attempting to filter Cosmos DB documents using OData and EntityFramework. My document structure consists of a Parent entity containing a Child object, as defined below:

public class Parent
{
    public Child Child { get; set; }
}

public class Child
{
    public Guid MyGuid { get; set; }
}

A sample JSON document looks like this:

{
   "Child": {
        "MyGuid": "dcb9d3f9-3133-48c6-864c-6fc0037584d4"
    }
}

I'm trying to filter all Parent documents where the Child.MyGuid property matches any value in a given GUID list. Here's an example query I'm using: $filter=Child/MyGuid in (dcb9d3f9-3133-48c6-864c-6fc0037584d4)

However, I'm encountering the following exception: "Method 'Cast' is not supported., Windows/10.0.19045 cosmos-netstandard-sdk/3.19.1"

"type": "Microsoft.Azure.Cosmos.Linq.DocumentQueryException",
"stacktrace": "   at Microsoft.Azure.Cosmos.Linq.ArrayBuiltinFunctions.Visit(MethodCallExpression methodCallExpression, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitNonSubqueryScalarExpression(Expression expression, ReadOnlyCollection`1 parameters, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitScalarExpression(Expression expression, ReadOnlyCollection`1 parameters, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ArrayBuiltinFunctions.ArrayContainsVisitor.VisitImplicit(MethodCallExpression methodCallExpression, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.BuiltinFunctionVisitor.Visit(MethodCallExpression methodCallExpression, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ArrayBuiltinFunctions.Visit(MethodCallExpression methodCallExpression, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitNonSubqueryScalarExpression(Expression expression, ReadOnlyCollection`1 parameters, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitScalarExpression(Expression expression, ReadOnlyCollection`1 parameters, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitBinary(BinaryExpression inputExpression, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitNonSubqueryScalarExpression(Expression expression, ReadOnlyCollection`1 parameters, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitScalarExpression(Expression expression, ReadOnlyCollection`1 parameters, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitWhere(ReadOnlyCollection`1 arguments, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.VisitMethodCall(MethodCallExpression inputExpression, TranslationContext context)
   at Microsoft.Azure.Cosmos.Linq.ExpressionToSql.Translate(Expression inputExpression, TranslationContext context)
   

I found the generated query from EntityFramework is

value(Microsoft.AspNet.OData.Query.Expressions.LinqParameterContainer+TypedLinqParameterContainer`1[System.Collections.Generic.List`1[System.Guid]]).TypedProperty.Cast().Contains(IIF(($it.Child == null), null, Convert($it.Child.MyGuid))))}

Not sure if the error is on EntityFramework side or CosmosDB client side, could you let me know how can I resolve this issue and successfully filter the Parent documents based on the Child.MyGuid property?

Environment summary
SDK Version: 3.19.0
OS Version (e.g. Windows, Linux, MacOSX): Windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant