我有以下方法:
public async Task<Boolean> MarkAsProvisioned( string requestId)
{
try
{
//populate the connection object:
GetStorageAccountConnectionData();
//lookup the record we need to change by the requestId.
var serviceClient = new TableServiceClient(
new Uri(connection.storageUri),
new TableSharedKeyCredential(connection.storageAccountName, connection.storageAccountKey));
var tableClient = serviceClient.GetTableClient(connection.tableName);
Azure.Response<Widget> response = tableClient.GetEntity<Widget>(
"mypartitionKey",
requestId);
Widget entity = response;
return true;
}
catch (Exception ex)
{
Console.Write(ex.Message);
return false;
}
}
我在呼叫 GetEntity() 的那一行遇到錯誤。錯誤是:
型別“MyProject.Models.Widget”不能用作泛型型別或方法“TableClient.GetEntity(string, string, IEnumerable, CancellationToken)”中的型別引數“T”。沒有從“MyProject.Models.Widget”到“Azure.Data.Tables.ITableEntity”的隱式參考轉換。csharp(CS0311)
我正在嘗試做這樣的事情:(偽代碼)
Widget entity = table.GetEntity<Widget >(partitionKey, rowKey);
entity.Name = newMessage;
table.UpdateEntity(entity, ETag.All, TableUpdateMode.Replace);
我看不出我哪里出錯了。
編輯 1
這是老班
using Newtonsoft.Json;
using System;
namespace MyProject.Models
{
public class Widget
{
[JsonProperty(PropertyName = "requestId")]
public string requestId { get; set; }
[JsonProperty(PropertyName = "status")]
public string status { get; set; }
[JsonProperty(PropertyName = "request")]
public WidgetRequest { get; set; }
}
這是新的:
using Newtonsoft.Json;
using Azure.Data.Tables;
using System;
using Azure;
namespace MyProject.Models
{
public class Widget:ITableEntity
{
public string PartitionKey { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string RowKey { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public DateTimeOffset? Timestamp { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public ETag ETag { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
[JsonProperty(PropertyName = "requestId")]
public string requestId { get; set; }
[JsonProperty(PropertyName = "status")]
public string status { get; set; }
[JsonProperty(PropertyName = "request")]
public WidgetRequest { get; set; }
}
uj5u.com熱心網友回復:
感謝Gaurav Mantri和點發布您的討論作為幫助其他社區成員的答案。
在類中添加
ITableEntity介面Widget以解決問題
using Newtonsoft.Json;
using Azure.Data.Tables;
using System;
using Azure;
namespace MyProject.Models
{
public class Widget:ITableEntity
{
public string PartitionKey { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string RowKey { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public DateTimeOffset? Timestamp { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public ETag ETag { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
[JsonProperty(PropertyName = "requestId")]
public string requestId { get; set; }
[JsonProperty(PropertyName = "status")]
public string status { get; set; }
[JsonProperty(PropertyName = "request")]
public WidgetRequest { get; set; }
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/431820.html
上一篇:Pythonnotebook-匯入帶有兩個字符的分隔符的資料檔案會導致錯誤
下一篇:像反向代理這樣的云服務?
