Vivek Misra
Vivek Misra

Reputation: 265

Rowkey.ToLower() while querying on Azure table throws Exception

Querying for an specific entity having e.RowKey.ToLower() throws an exception

CustomerEntity customerEntity = (from e in serviceContext.CreateQuery<CustomerEntity>("Customer")
                                     where e.RowKey.ToLower() == firstName.ToLower()                                         
                                     select e).FirstOrDefault();

Basically i want to check for case insensitive username..Azure table is managed by our partner so i can not instruct them to enter the User entry into table in lower case.

I need to handle this in code.

REgards, Vivek

Upvotes: 1

Views: 846

Answers (2)

Mark Rendle
Mark Rendle

Reputation: 9414

ToLower() isn't valid as part of the filter expression because Table Storage doesn't support that as an operation.

You have two options:

  1. Ensure that all the data you put in is lower-case. If you also need the upper/mixed case version, put it in another column.
  2. Pull back all the data and do the filter in memory. This is valid if you've only got a small number of records.

Upvotes: 3

Evan
Evan

Reputation: 6133

You're getting an exception because the ToLower() method is not a supported method in Azure.

I think you could do the comparison this way instead

where e.RowKey.Equals(username, StringComparison.InvariantCultureIgnoreCase);

It should accomplish what you're trying to do, but it uses the supported Equals() method instead.

Upvotes: 0

Related Questions