我想读,我已经存储在Azure存储表的价值。当检索到的实体,在提琴手,我可以看到的响应具有正确的值,即:
{
"odata.etag":"W/\"datetime'2019-01-24T20%3A23%3A58.3605274Z'\"",
"PartitionKey":"0029c461-74b9-47a7-955b-28e07b1905ab",
"RowKey":"09a79860-f568-481c-9641-9a1d53ebd678",
"Timestamp":"2019-01-24T20:23:58.3605274Z",
"AdjustmentId":"[GUID]",
"CompanyName":"[CompanyNme]",
"CustomerId":"[GUID]",
"[email protected]":"Edm.DateTime",
"Date":"2019-01-24T20:23:49.9487324Z",
"FinalQuantity":35,
"Id":"[GUID]",
"InitialQuantity":36.0,
"OfferName":"[Product]",
"Requester":"[User]",
"Status":"Accepted",
"StatusMessage":"Created",
"Type":"QuantityAdjustment"
}
然而,当我在我的C#代码与此resoponse工作,InitialQuantity设置为0。我使用的是微软的Azure WebJobs扩展存储v3.0.3和WindowsAzure.Storage v9.3.3。
该Azure存储SDK映射这对实体类如下:
public class Transaction : TableEntity, ITransaction
{
/// <summary>
/// Gets or sets the adjustment identifier.
/// </summary>
/// <value>The adjustment identifier.</value>
public string AdjustmentId { get; set; }
/// <summary>
/// Gets or sets the name of the company.
/// </summary>
/// <value>The name of the company.</value>
public string CompanyName { get; set; }
/// <summary>
/// Gets or sets the customer identifier.
/// </summary>
/// <value>The customer identifier.</value>
public string CustomerId { get; set; }
/// <summary>
/// Gets or sets the Transaction's date. Should be generated on creation.
/// </summary>
/// <value>The date.</value>
public DateTime? Date { get; set; }
/// <summary>
/// Gets or sets the final quantity following the transaction.
/// </summary>
/// <value>The final quantity.</value>
public int FinalQuantity { get; set; }
/// <summary>
/// Gets or sets the transaction identifier. Should be a GUID in string format. This is
/// generated when a new Transaction is created.
/// </summary>
/// <value>The identifier.</value>
public string Id { get; set; } = Guid.NewGuid().ToString().ToLower();
/// <summary>
/// Gets or sets the initial quantity.
/// </summary>
/// <value>The initial quantity.</value>
public int InitialQuantity { get; set; }
/// <summary>
/// Gets or sets the offer identifier.
/// </summary>
/// <value>The offer identifier.</value>
public string OfferId { get; set; }
/// <summary>
/// Gets or sets the name of the offer.
/// </summary>
/// <value>The name of the offer.</value>
public string OfferName { get; set; }
/// <summary>
/// Gets or sets the requester.
/// </summary>
/// <value>The requester.</value>
public string Requester { get; set; }
/// <summary>
/// Gets or sets the status. Set to pending by default.
/// </summary>
/// <value>The status.</value>
public string Status { get; set; } = TransactionStatus.Pending;
/// <summary>
/// Gets or sets the status message.
/// </summary>
/// <value>The status message.</value>
public string StatusMessage { get; set; }
/// <summary>
/// Gets or sets the type. Should be set using the constants in the <see
/// cref="T:LicenseAdjustmentManagement.Infrastructure.TransactionTypes"/> class.
/// </summary>
/// <value>The type.</value>
public string Type { get; set; }
public string ToJson()
{
return JsonConvert.SerializeObject(this);
}
}
调用实体代码。
var storageAccount = CloudStorageAccount.Parse("[ConnectionString]");
var tableClient = storageAccount.CreateCloudTableClient();
var transactionsTable = tableClient.GetTableReference("Transactions");
var query = TableQuery<Transaction>().Where(TableQuery.GenerateFilterCondition("Id", QueryComparisons.Equal, "[GUID]"));
var results = await transactionsTable.ExecuteQuerySegmentedAsync(query, default(TableContinuationToken)).AsEnumerable();
var transaction = results.First();
所有其他值都被正确读取,但与InitialValue始终为0有什么建议?
编辑:正如KSib以下建议,将与InitialValue被序列化为decimal
或double
所以当它的反序列化作为int
,它临危INT,0
的默认值。任何想法,为什么当它宣布为decimal
这件事被序列化为int
?
你试图反序列化小数为int,想必和而不是抛出一个异常,我要承担它只是将该属性设置为default(int)
这是0