[CSHARP-860] asp.net web api / odata $select and datetime queries problems Created: 06/Nov/13  Updated: 20/Mar/14  Resolved: 07/Nov/13

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.8, 1.8.1, 1.8.3
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Huseyin Yurtseven Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CSHARP-601 Linq to Aggregation Framework Closed

 Description   

Hi,

We use asp.net web api 2 with OData Support and we use $select option on odata, when we try to use $select option we get

MongoQueryException("Skip and Take may only be used in conjunction with each other and cannot be separated by other operations.");

but when i comment that line i works correctly.

Another exception when we try to use OData date time queries is

Unsupported where clause: ((Nullable<DateTime>)x.StartDate > (Nullable<DateTime>)DateTime:(2013-08-01T00:00:00, Unspecified)).

so we cannot use date time gt ge or lt le queries and when we add following lines to PredicateTranslator BuildComparrisonQuery function it worlks again.

 BsonSerializationInfo serializationInfo = null;
            var value = constantExpression.Value;
 
            var unaryExpression = variableExpression as UnaryExpression;
            if (unaryExpression != null && (unaryExpression.NodeType == ExpressionType.Convert || unaryExpression.NodeType == ExpressionType.ConvertChecked))
            {
                if (unaryExpression.Operand.Type.IsEnum)
                {
                    var enumType = unaryExpression.Operand.Type;
                    if (unaryExpression.Type == Enum.GetUnderlyingType(enumType))
                    {
                        serializationInfo = _serializationInfoHelper.GetSerializationInfo(unaryExpression.Operand);
                        value = Enum.ToObject(enumType, value); // serialize enum instead of underlying integer
                    }
                }
                else if (
                    unaryExpression.Type.IsGenericType &&
                    unaryExpression.Type.GetGenericTypeDefinition() == typeof(Nullable<>) &&
                    unaryExpression.Operand.Type.IsGenericType &&
                    unaryExpression.Operand.Type.GetGenericTypeDefinition() == typeof(Nullable<>) &&
                    unaryExpression.Operand.Type.GetGenericArguments()[0].IsEnum)
                {
                    var enumType = unaryExpression.Operand.Type.GetGenericArguments()[0];
                    if (unaryExpression.Type.GetGenericArguments()[0] == Enum.GetUnderlyingType(enumType))
                    {
                        serializationInfo = _serializationInfoHelper.GetSerializationInfo(unaryExpression.Operand);
                        if (value != null)
                        {
                            value = Enum.ToObject(enumType, value); // serialize enum instead of underlying integer
                        }
                    }
                } else {
                    // FIX
                    serializationInfo = _serializationInfoHelper.GetSerializationInfo(unaryExpression.Operand);
                }
            }

Thanks



 Comments   
Comment by Craig Wilson [ 07/Nov/13 ]

Sounds like you've resolved this. I've seen similar issues. The OData implementations something throw interesting operators in that don't need to be there. We are working on re-writing our linq provider, so potentially some of these issues will get resolved that way as well. For now, I think using OData 2.0 makes sense.

Comment by Huseyin Yurtseven [ 07/Nov/13 ]

Hi Craig,

Thanks for your quick response,

I was making a demo project to send you but i noticed there is no problem with Web Api 2, OData 5 and MongoDB Release 1.8.3, so i think problem is on Web Api 1.

We can upgrade our project to Web Api 2.

Thanks for your helps.

Comment by Craig Wilson [ 06/Nov/13 ]

Hi Huseyin,
Thanks for the report. I'm not surprised something doesn't work with regardes to OData. It tends to do some weird things every once in a while.

What would help us out greatly would be a project demonstrating this issue such that we can prove it's been fixed.

Thanks,
Craig

Generated at Wed Feb 07 21:38:02 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.