While querying an Azure storage table I get an exception.
Here is my query:
tableClient.QueryAsync<Resource>(resource => resource.PartitionKey == projectId.ToString()
&& String.Equals(resource.FullName, fullName, StringComparison.InvariantCultureIgnoreCase));
resource.FullName
and fullName
are both of type string
.
But this incurs the exception...
Incorrect number of arguments supplied for call to method 'Boolean Equals(System.String, System.String, System.StringComparison)' (Parameter 'method')
And similarly, if I add an additional condition (before the String.Equals
)...
&& !String.IsNullOrWhiteSpace(resource.FullName)
... this incurs the exception...
Method IsNullOrWhiteSpace not supported.
If I change the string comparison to...
resource.FullName.ToLower() == fullName.ToLower()
... then I'm told that ToLower
is not supported.
What's going on here? Why can't I call String.Equals
or String.IsNullOrWhiteSpace
on a property which is of type string
? Am I misunderstanding something, and resource.FullName
is actually not a string
?
Please follow the below suggestions and check if that helps.
String.Equals
to String.Compare?String.Compare
method with StringComparison.OrdinalIgnoreCase option to achieve case-insensitive comparison:tableClient.QueryAsync<Resource>(resource =>
resource.PartitionKey == projectId.ToString() &&
String.Compare(resource.FullName, fullName, StringComparison.OrdinalIgnoreCase) == 0);
String.IsNullOrEmpty
method along with String.Trim method:tableClient.QueryAsync<Resource>(resource =>
resource.PartitionKey == projectId.ToString() &&
!String.IsNullOrEmpty(resource.FullName) &&
!String.IsNullOrEmpty(resource.FullName.Trim()));
Hope this helps.