我试图根据分区键和行键成功检索实体,但当我尝试转换它时,它会抛出无效的转换异常。 我查看了 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
这是我的课
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>
关于c# - 无法将动态表实体转换为自定义实体 Azure 表存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44053834/