Azure / azure-storage-net

Microsoft Azure Storage Libraries for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CloudTable.ExecuteQuery difference in VB.NET vs C#

extellior opened this issue · comments

Which service(blob, file, queue, table) does this issue concern?

CloudTable.ExecuteQuery

Which version of the SDK was used?

azure.core 1.12.0
azure.data.tables 12.0.0-beta6
azure.storage.common 12.8.0-beta2
microsoft.azure.cosmos 3.18.0-preview
microsoft.azure.cosmos.table 2.0.0-preview

Which platform are you using? (ex: .NET Core 2.1)

.NET Framework 4.7.2

What problem was encountered?

In C#, calling CloudTable.ExecuteQuery requires only 1 parameter (a TableQuery). In VB.NET, same libraries and framework, it says there's no such matching overload, and it also wants RequestOptions and an OperationContext parameters.

How can we reproduce the problem in the simplest way?

    Dim storageAcct As CloudStorageAccount = CloudStorageAccount.Parse(ConnStr)
    Dim tableClient As CloudTableClient = storageAcct.CreateCloudTableClient()
    Dim table As CloudTable = tableClient.GetTableReference("licensedata")
    Dim licenseQuery As TableQuery(Of LicenseEntity) = New TableQuery(Of LicenseEntity)().Where(TableQuery.CombineFilters(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, cmbProduct.Text), TableOperators.[And], TableQuery.GenerateFilterCondition("email", QueryComparisons.Equal, txtLicenseQueryEmail.Text)))
    Dim licMatches = table.ExecuteQuery(licenseQuery)

    If licMatches.Any() Then
        For Each license As LicenseEntity In licMatches
        Next
    Else
        MessageBox.Show("No matches")
    End If

Have you found a mitigation/solution?

I can do this in C# and it works fine - it successfully retrieves data from an Azure table. But you can't do the same thing in VB.NET.

CloudStorageAccount storageAcct = CloudStorageAccount.Parse(ConnStr);
CloudTableClient tableClient = storageAcct.CreateCloudTableClient();
CloudTable table = tableClient.GetTableReference("licensedata");
TableQuery<LicenseEntity> licenseQuery = new TableQuery<LicenseEntity>().Where(
    TableQuery.CombineFilters(
        TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, cmbProduct.Text),
        TableOperators.And,
        TableQuery.GenerateFilterCondition("email", QueryComparisons.Equal, txtLicenseQueryEmail.Text)));

var licMatches = table.ExecuteQuery(licenseQuery);
if (licMatches.Any())
{
    foreach (LicenseEntity license in licMatches)
    {
        // do stuff...          
    }
}
else
{
    MessageBox.Show("No matches");
}

Hold off any action/review on this temporarily.

I would delete this if there was a way to do so. The problem is the result of a coding error in my entity class.

I was using this:

Implements Azure.Data.Tables.ITableEntity

But it needed to be this:

Inherits Microsoft.Azure.Cosmos.Table.TableEntity

Otherwise, my code (above) is perfectly fine. I still think it's pretty weird that caused this particular problem, though.