我是初學者,想了解更多關於Azure的表存儲,但我胡說,這個簡單的例子突破:無法保存引用類型
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;
}
}
}
它看起來像Azure中不能存儲引用類型。當我保存,然後檢索的人,名稱是檢索的人空,因此,我想從人的名稱屬性來獲取名字的時候得到一個空指針異常:
string firstname = ((Person)retrievedResult.Result).Name.FirstName;
我沒有閱讀這是不可能的任何地方。我用這個作爲學習的入口:http://www.windowsazure.com/en-us/documentation/articles/storage-dotnet-how-to-use-table-storage-20/。通過閱讀「引進」能夠服務的網絡規模應用
- TB的存儲
- 使用聚集索引
- 使用OData協議和LINQ查詢與WCF數據服務.NET庫
訪問數據快速查詢數據,我的考試應該有可能。但我猜這是不可能的?
你得到的錯誤是什麼? –
被剔除者的姓名爲空。所以我得到一個空指針錯誤。在我看來,錯誤是我無法存儲參考類型。 – mslot
嗯..我之前沒有使用過Azure庫,但是在我聽到您的Person對象不存在於表中時,當您嘗試檢索它時。我很懷疑在插入後立即檢索對象。 –