0
我想基於分區鍵和行鍵替換我的表上的實體成功,但是當我嘗試轉換它時,它會引發無效的轉換異常。 我看了看MSDN文檔,那就是刪除正確的方式,甚至提出一定要遵循指南,創建一個實體未能將動態表實體投射到自定義實體Azure表存儲
實體屬性,你想在一個表來存儲必須的公共屬性鍵入,並支持獲取和設置值。此外,你的實體類型必須公開一個參數的構造函數
這是我的課
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...
我在這裏失蹤了什麼?
完美的感謝! – Harry