无法将动态 Table 实体转换为自定义实体 Azure Table 存储

Failed to cast Dynamic Table entity to custom Entity Azure Table storage

我正在尝试根据分区键和行键替换我 table 上的一个实体,成功检索到该实体,但是当我尝试转换它时,它会抛出无效转换异常。 我查看了 MSDN 文档,这是删除的正确方法,甚至确保遵循创建实体的指南

Entity properties you'd like to store in a table must be public properties of the type, and support both getting and setting of values. Also, your entity type must expose a parameter-less constructor

这是我的class

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

    public BasicAsset(string name)
    {
        Name = name;
    }


    [IsFilterable, IsSortable, IsSearchable]
    public string Name { get; set; }

    [IsFilterable, IsSortable]
    public int Version { get; set; }
}

这是我在异常点的代码

TableOperation retreiveOperation = TableOperation.Retrieve("Orginization", result.Results[0].Document.RowKey);
TableResult toDelete = await table.ExecuteAsync(retreiveOperation);
BasicAsset toReplaceAsset = (BasicAsset) toDelete.Result;
//Change what is new here
toReplaceAsset.Version = asset.Version;
TableOperation replaceOperation = TableOperation.Replace(toReplaceAsset);

错误

   e = {System.InvalidCastException: Unable to cast object of type 'Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity' to type 'AssetSynch.Models.BasicAsset'.
   at AssetSynch.Controllers.TableStorageViewFunctions.<>c__DisplayClass0_0.<<UpdateLattestAssetVe...

我在这里错过了什么?

而不是 Retrieve 尝试使用 Retrieve<BasicAsset>,或者您可以简单地调用 ExecuteQuery<BasicAsset>