简体   繁体   English

没有来自的装箱转换或类型参数转换 <T> 到&#39;Microsoft.WindowsAzure.Storage.Table.ITableEntity&#39;

[英]There is no boxing conversion or type parameter conversion from <T> to 'Microsoft.WindowsAzure.Storage.Table.ITableEntity'

Background 背景

I'm trying to receive some values from an Azure storage table following the following tutorial. 我正在尝试按照以下教程从Azure存储表中接收一些值。

Retrieve all entities in a partition - https://docs.microsoft.com/en-us/azure/cosmos-db/table-storage-how-to-use-dotnet 检索分区中的所有实体-https : //docs.microsoft.com/zh-cn/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. 我80%确信问题与第二个错误无关,因为我的模型是带有公共无参数构造函数的非抽象类型。

Error Messages 错误讯息

The type 'AzureStorageTableEntites' cannot be used as type parameter 'TElement' in the generic type or method 'CloudTable.ExecuteQuery(TableQuery, TableRequestOptions, OperationContext)'. 在通用类型或方法“ CloudTable.ExecuteQuery(TableQuery,TableRequestOptions,OperationContext)”中,类型“ AzureStorageTableEntites”不能用作类型参数“ TElement”。 There is no boxing conversion or type parameter conversion from 'AzureStorageTableEntites' to 'Microsoft.WindowsAzure.Storage.Table.ITableEntity'. 没有从“ AzureStorageTableEntites”到“ 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)' “ AzureStorageTableEntites”必须是具有公共无参数构造函数的非抽象类型,以便在通用类型或方法“ CloudTable.ExecuteQuery(TableQuery,TableRequestOptions,OperationContext)”中将其用作参数“ TElement”

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 MiJobsMessageQueueToggle { 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 MiJobsExceptionLogToggle { 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))
        {

        }
    }

seems to be a typo issue. 似乎是一个错字问题。 the error you copied says AzureStorageTableEntites vs the class you copied is called AzureStorageTableEntities. 您复制的错误显示AzureStorageTableEntites与您复制的类称为AzureStorageTableEntities。 The class you copied AzureStorageTableEntities looks good, it already implements ITableEntity through its base class, have parameterless ctor and it is non abstract. 您复制AzureStorageTableEntities的类看起来不错,它已经通过其基类实现了ITableEntity ,具有无参数的ctor,并且它是非抽象的。 If you fix the typo and use that class you should be good to go. 如果您修正了拼写错误并使用了该类,那么您应该很好。 Also use the generic version of ExecuteQuery 也使用ExecuteQuery的通用版本

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()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将字符串转换为 Microsoft.WindowsAzure.Storage.Table.ITableEntity? - How can i convert a string to Microsoft.WindowsAzure.Storage.Table.ITableEntity? 没有来自“ T”的装箱转换或类型参数转换 - There is no boxing conversion or type parameter conversion from 'T' 没有装箱或类型参数转换 - There is no boxing or type parameter conversion Blazor:没有从“T”到“System.IComparable”的装箱转换或类型参数转换<t></t> - Blazor: There is no boxing conversion or type parameter conversion from 'T' to 'System.IComparable<T> 没有从“ TKey”到“ System.IEquatable”的装箱转换或类型参数转换 - There is no boxing conversion or type parameter conversion from 'TKey' to 'System.IEquatable' 通用Type参数没有装箱或类型参数转换 - No boxing or type parameter conversion for generic Type parameter 类型“int”不能用作泛型方法中的类型参数“T”。 'int' 没有拳击转换 - The type 'int' cannot be used as type parameter 'T' in the generic method. There is no boxing conversion from 'int' 从&#39;V&#39;到&#39;System.IEquatable没有装箱转换或类型参数转换 <V> “ - There is no boxing conversion or type parameter conversion from 'V' to 'System.IEquatable<V>' 通用类型。 没有装箱转换或类型参数转换 - Generic types. There is no boxing conversion or type parameter conversion 没有使用Mono的通用Type参数的装箱或类型参数转换 - No boxing or type parameter conversion for generic Type parameter with Mono
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM