I am a beginner, and want to learn more about Azure Table Storage, but I am babbled that this simple example breaks:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
namespace AzureTablesTest
{
public class PersonName
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class Person : TableEntity
{
public PersonName Name { get; set; }
public int Age { get; set; }
public Person()
{
}
public Person(string lastname, string firstname)
{
RowKey = firstname;
PartitionKey = lastname;
Name = new PersonName { FirstName = firstname, LastName = lastname };
}
}
class Program
{
static void Main(string[] args)
{
// Retrieve the storage account from the connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
// Create the table client.
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
// Create the table if it doesn't exist.
CloudTable table = tableClient.GetTableReference("people");
table.CreateIfNotExists();
Person p = new Person("Foo", "Bar");
TableOperation insertOperation = TableOperation.Insert(p);
// Execute the insert operation.
table.Execute(insertOperation);
TableOperation retrieveOperation = TableOperation.Retrieve<Person>("Foo", "Bar");
// Execute the retrieve operation.
TableResult retrievedResult = table.Execute(retrieveOperation);
string firstname = ((Person)retrievedResult.Result).Name.FirstName;
}
}
}
It looks like Azure cannot store reference types. When I save, and then retrieve Person, Name is null on the person retrieved, and therefore I am getting a null pointer exception when trying to get the FirstName from the Name property of the person:
string firstname = ((Person)retrievedResult.Result).Name.FirstName;
I have not read anywhere that this is not possible. I use this as a entry of learning: http://www.windowsazure.com/en-us/documentation/articles/storage-dotnet-how-to-use-table-storage-20/. By reading the "introduction"
- Storing TBs of structured data capable of serving web scale applications
- Storing datasets that don't require complex joins, foreign keys, or stored procedures and can be denormalized for fast access
- Quickly querying data using a clustered index
- Accessing data using the OData protocol and LINQ queries with WCF Data Service .NET Libraries
in my eyes, my example should be possible. But I guess it is not possible?