I'm trying to read values that I have stored in an Azure Storage Table. When I retrieve the entity, in Fiddler, I can see the response as having the correct value, i.e.:
{
"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"
}
However, when I work with this resoponse in my C# code, the InitialQuantity is set to 0. I'm using Microsoft Azure WebJobs Extensions Storage v3.0.3 and WindowsAzure.Storage v9.3.3.
The entity class that the Azure Storage SDK maps this to is below:
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);
}
}
Code that calls the entities.
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();
All the other values are being read correctly, but the InitialValue is always 0. Any suggestions?
Edit: As suggested by KSib below, the InitialValue is being serialized as a decimal
or double
so when it's deserialized as an int
, it recieves the default value of int, 0
. Any idea why this thing is being serialized as a decimal
when it's declared as in int
?
in my C# code
you forgot to add your code – Dan Wilson