using System;
using System.Linq;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
namespace AzureStorageTableSearch
{
class Person : TableEntity
{
public Person()
{
PartitionKey = "";
RowKey = Guid.NewGuid().ToString("N");
}
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime BirthDate { get; set; }
public string FullName => FirstName + " " + LastName;
public int Age => DateTime.Now.Year - BirthDate.Year;
public override string ToString()
{
return FullName + " " + Age;
}
}
class Program
{
static void Main(string\[\] args)
{
var account = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("Default"));
var client = account.CreateCloudTableClient();
var table = client.GetTableReference("persons");
table.DeleteIfExists();
table.Create();
table.Execute(TableOperation.Insert(new Person
{
FirstName = "Alexandr",
LastName = "Marchenko",
BirthDate = new DateTime(1985, 3, 11)
}));
table.Execute(TableOperation.Insert(new Person
{
FirstName = "Maria",
LastName = "Marchenko",
BirthDate = new DateTime(1987, 6, 11)
}));
foreach (var person in table.CreateQuery<Person>().Where(p => p.LastName.Equals("Marchenko")))
{
Console.WriteLine(person);
}
Console.ReadKey();
}
}
}