Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-860

asp.net web api / odata $select and datetime queries problems

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.8, 1.8.1, 1.8.3
    • Component/s: None
    • None

      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

            Assignee:
            Unassigned Unassigned
            Reporter:
            hyurtseven@dogantv.com.tr Huseyin Yurtseven
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: