1
votes

Background

I'm trying to receive some values from an Azure storage table following the following tutorial.

Retrieve all entities in a partition - https://docs.microsoft.com/en-us/azure/cosmos-db/table-storage-how-to-use-dotnet

Question

I am receiving two errors as shown below, and I can't work out how to remedy them.

I'm 80% sure the problem doesn't pertain to the second error, as my model is of non-abstract type with a public parameterless constructor.

Error Messages

The type 'AzureStorageTableEntites' cannot be used as type parameter 'TElement' in the generic type or method 'CloudTable.ExecuteQuery(TableQuery, TableRequestOptions, OperationContext)'. There is no boxing conversion or type parameter conversion from 'AzureStorageTableEntites' to 'Microsoft.WindowsAzure.Storage.Table.ITableEntity'.

and

'AzureStorageTableEntites' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'TElement' in the generic type or method 'CloudTable.ExecuteQuery(TableQuery, TableRequestOptions, OperationContext)'

The errors indicate the problem in this part of the calling method:

       // Print fields.
        foreach (AzureStorageTableEntities entity in table.ExecuteQuery<AzureStorageTableEntities>(query))
        {
           
        }

More specifically over this part:

table.ExecuteQuery<AzureStorageTableEntities>(query)

Code

My Model consist of:

 public class AzureStorageTableEntities : TableEntity
    {
        public AzureStorageTableEntities() { }

        public bool MessageQueueToggle { get; set; }
        public bool DeadLetterQueueToggle { get; set; }
        public bool ServiceBusQueueToggle { get; set; }
        public bool MiJobsMessageAgeToggle { get; set; }
        public DateTime SpecificCheckTime { get; set; }
        public int HourlyCheckInternalToggle { get; set; }
        public bool ExceptionLogToggle { get; set; }
        public bool SpecificCheckTimeToggle { get; set; }
    }

Calling Method:

   private void GetStorageTableValues<AzureStorageTableEntities>()
    {
        // Retrieve the storage table name.
        var tableName = CloudConfigurationManager.GetSetting("AzureConfigTableName");

        // Retrieve the storage account from the connection string.
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

        // Create the table client.
        CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

        // Create the CloudTable object that represents the storage table.
        CloudTable table = tableClient.GetTableReference(tableName);

        TableQuery<AzureStorageTableEntities> query = new TableQuery<AzureStorageTableEntities>()
        .Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Key"));

        // Print fields.
        foreach (AzureStorageTableEntities entity in table.ExecuteQuery<AzureStorageTableEntities>(query))
        {

        }
    }
2

2 Answers

2
votes

The problem was the generic type in the method signature. Once I removed this everything worked as expected.

private void GetStorageTableValues<AzureStorageTableEntities>()

Changed to this.

private void GetStorageTableValues()
1
votes

seems to be a typo issue. the error you copied says AzureStorageTableEntites vs the class you copied is called AzureStorageTableEntities. The class you copied AzureStorageTableEntities looks good, it already implements ITableEntity through its base class, have parameterless ctor and it is non abstract. If you fix the typo and use that class you should be good to go. Also use the generic version of ExecuteQuery