locked
$filter value case sensitivity on IQueryable property RRS feed

  • Question

  • Hi, is it possible to suppress the case sensitivity when filtering on field. 

     

      public class Address
      {
        public int ID { get; set; }
        public string Line1 { get; set; }
        public string Postcode { get; set; }
      }
      
      public class AddressData
      {
        private List<Address> addresses = new List<Address>
                             {
                               new Address {ID = 1, Line1 = "1", Postcode = "ST1 3RD"},
                               new Address {ID = 2, Line1 = "2", Postcode = "ST1 3RD"},
                               new Address {ID = 3, Line1 = "3", Postcode = "ST1 3RD"},
                               new Address {ID = 4, Line1 = "4", Postcode = "ST1 3Rd"},
                               new Address {ID = 5, Line1 = "5", Postcode = "ST1 3Rd"},
                               new Address {ID = 6, Line1 = "6", Postcode = "ST1 3RD"},
                               new Address {ID = 7, Line1 = "7", Postcode = "ST1 3RD"},
                               new Address {ID = 8, Line1 = "1", Postcode = "DE7 4TG"},
                               new Address {ID = 9, Line1 = "2", Postcode = "DE7 4TG"},
                               new Address {ID = 10, Line1 = "3", Postcode = "DE7 4TG"},
                               new Address {ID = 11, Line1 = "4", Postcode = "DE7 4TG"},
                               new Address {ID = 12, Line1 = "5", Postcode = "DE7 4TG"}
                             };
    
        public IQueryable<Address> Addresses
        {
          get
          {
            return addresses.AsQueryable();
          }
        }
      }
    
        [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
        public class AddressService : DataService<AddressData>
        {
          public static void InitializeService(DataServiceConfiguration config)
          {
            config.UseVerboseErrors = true;
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
            config.SetEntitySetAccessRule("*", EntitySetRights.All);
            config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
          }
    
          protected override AddressData CreateDataSource()
          {
            return new AddressData();
          }
        }
    

     

    Query this data with 

    $filter=Postcode eq 'st1 3rd'

    and I get no record! 

    I guess that I could add a RequestInterceptor and change the value in the requestContext.RequestMessage.Headers.To.AbsoluteUri ToUpper() but that seems like a right hack to me...!

     


    Tuesday, September 21, 2010 3:23 PM

Answers

  • Hi Jim,

     The WCF Data Services framework doesn't make any assumptions on the data flowing through the system.
     However, we do allow you to make certain modifications on the data while comparing results.
     What you are trying to do above can be done via functions in the Uri space, try this query :

     $filter=tolower(Postcode) eq 'st1 3rd'

     This way, you can convert the post code to lower case before comparision.
     Here's a complete list of functions : http://www.odata.org/developers/protocols/uri-conventions


    Phani Raj Astoria http://blogs.msdn.com/PhaniRaj
    • Marked as answer by JimBobPop Wednesday, September 22, 2010 9:17 AM
    Tuesday, September 21, 2010 5:25 PM
    Moderator

All replies

  • Hi Jim,

     The WCF Data Services framework doesn't make any assumptions on the data flowing through the system.
     However, we do allow you to make certain modifications on the data while comparing results.
     What you are trying to do above can be done via functions in the Uri space, try this query :

     $filter=tolower(Postcode) eq 'st1 3rd'

     This way, you can convert the post code to lower case before comparision.
     Here's a complete list of functions : http://www.odata.org/developers/protocols/uri-conventions


    Phani Raj Astoria http://blogs.msdn.com/PhaniRaj
    • Marked as answer by JimBobPop Wednesday, September 22, 2010 9:17 AM
    Tuesday, September 21, 2010 5:25 PM
    Moderator
  • Thanks for the help Phani.

    Wednesday, September 22, 2010 9:19 AM