ã¯ããã«
ããŒã¿ãä¿åããããã®å€ãã®ãªãã·ã§ã³ã®äžã§ãã¯ã©ãŠãå ã®æ å ±ã¹ãã¬ãŒãžãç 究ããããã®æ°ããèå³æ·±ãæè¡ãééããªã匷調ããããšãã§ããŸãã çŸæç¹ã§ã¯ããã®çš®ã®ãµãŒãã¹ãæäŸããããã®ããã€ãã®ãµãŒãã¹ãããããããã¯æã§æ°ããããšãã§ããŸã-ãããã¯ãAmazon WebãµãŒãã¹ãSun CloudãWindows Azureã§ãã ãããã®åãµãŒãã¹ã¯ãããŒã¿ã«ã¢ã¯ã»ã¹ããããã®ç¬èªã®ã€ã³ã¿ãŒãã§ã€ã¹ãæäŸããŸãããã®èšäºã§ã¯ãWindows AzureãµãŒãã¹ã«ã€ããŠè©³ãã説æããŸãã
ãã®ã¯ã©ãŠãã³ã³ãã¥ãŒãã£ã³ã°ãã©ãããã©ãŒã ã¯ã3çš®é¡ã®æ å ±ã¹ãã¬ãŒãžãµãŒãã¹ãæäŸããŸãã
- BlobãµãŒãã¹ãããã¹ããšãã€ããªæ å ±ãç¹å¥ã«ç·šæãããBlobã³ã³ããã«ä¿åã§ããŸãã
- ãã¥ãŒã¯ãã¡ãã»ãŒãžã®ç¡å¶éã®ã¹ãã¬ãŒãžãæŽçã§ãããµãŒãã¹ã§ãïŒããã¥ã¡ã³ãã«ãããšãåã¡ãã»ãŒãžã¯8 kbãè¶ ããããšã¯ã§ããŸããïŒã
- ããŒãã«ãµãŒãã¹ã§ã¯ãããŒãã«ã«æ§é åãããããŒã¿ãä¿åã§ããREST APIãä»ããŠã¢ã¯ã»ã¹ã§ããŸãã
äžèšã®æåŸã®ãµãŒãã¹ã§ããããŒãã«ã¹ãã¬ãŒãžã¯ãäžèŠãããšãªã¬ãŒã·ã§ãã«ããŒãã«ã¹ãã¬ãŒãžã®é¡äŒŒç©ãšèŠãªãããšãã§ããŸãããèšäºã®éçšã§ãã®æŠå¿µã«ããã€ãã®éèŠãªéããããããšãæããã«ããŸãã
ãã®ã¹ãã¬ãŒãžã«ã¯ããŒãã«ïŒããŒãã«ïŒãå«ããããšãã§ããŸããããŒãã«ã¹ãã¬ãŒãžã³ã³ã»ããã®ããŒãã«ã¯ãšã³ãã£ãã£ïŒãšã³ãã£ãã£ïŒã®ã³ã¬ã¯ã·ã§ã³ã§ããããªã¬ãŒã·ã§ãã«ã¹ãã¬ãŒãžã®ã¿ãã«ã«äŒŒãŠããŸãããšã³ãã£ãã£ã¯ç¹å®ã®ããããã£ïŒããããã£ïŒã®ã»ããã§ãããååãšåä»ãã®å€ã®ãã¢ããšã³ãã£ãã£ã¯ãªã¬ãŒã·ã§ãã«ãªããžããªã®ããŒãã«ã®ãã£ãŒã«ãã«äŒŒãŠããŸãã ããã§ãããŒãã«ã¹ãã¬ãŒãžã®ããŒãã«ã¯æ ŒçŽããããšã³ãã£ãã£ã®æ§é ãæå®ããŠããªãããšã«æ³šæããŠãã ãããããããæ ŒçŽããããšã³ãã£ãã£ã¯ããŸããŸãªããããã£ãå«ãããšãã§ããŸãããåãããŒãã«ã«ãããŸãã
- ããŒãã«åãçæããããã®ã«ãŒã«ã詳现ã«æ€èšããŠãã ããã
- ããŒãã«åã«ã¯è±æ°åã®ã¿ãå«ããããšãã§ããŸãã
- ããŒãã«åãæ°åã§å§ããããšã¯ã§ããŸããã
- ããŒãã«åã§ã¯å€§æåãšå°æåãåºå¥ãããŸãã
- ããŒãã«åã¯3ã63æåã§ãªããã°ãªããŸããã
- ããããã£åã¯å€§æåãšå°æåãåºå¥ããã255æåãè¶ ããããšã¯ã§ããŸããã
- åãšã³ãã£ãã£ã«ã¯ãæ倧253åã®ãŠãŒã¶ãŒå®çŸ©ããããã£ãå¿ èŠã§ãã
- åãšã³ãã£ãã£ã®åèšããŒã¿ãµã€ãºã¯1 mb以äžã§ããå¿ èŠããããŸãã
- åãšã³ãã£ãã£ã«ã¯ã以äžã§èª¬æãã3ã€ã®ã·ã¹ãã ããããã£ãå«ãŸããŠããå¿ èŠããããŸãã
ãšã³ãã£ãã£ã®ã·ã¹ãã ããããã£ã
ãã©ã³ã¹ã®åããããŒã¿ã®èªã¿èŸŒã¿ããµããŒãããã«ã¯ãã¹ãã¬ãŒãžå ã®ããŒãã«ãããŒãã£ã·ã§ã³åå²ïŒããŒãã£ã·ã§ã³ïŒã§ãããããã©ã®ãšã³ãã£ãã£ãã©ã®ããŒãã£ã·ã§ã³ã«å±ããŠããããæ確ã«ç€ºãããã«ããã®ãšã³ãã£ãã£ãé 眮ãããŠããããŒãã«ã®ããŒãã£ã·ã§ã³ãäžæã«èå¥ããPartitionKeyããããã£ãå«ããå¿ èŠããããŸãã
æ ŒçŽãããåãšã³ãã£ãã£ã®å¥ã®å¿ é ããããã£ã¯ãç¹å®ã®ã»ã¯ã·ã§ã³ã®ç¹å®ã®ãšã³ãã£ãã£ãæ¢ã«èå¥ããRowKeyããããã£ã§ãã 説æãããŠããRowKeyããã³PartitionKeyããããã£ã¯ãåãšã³ãã£ãã£ã®ãã©ã€ããªããŒãã¢ã圢æããæ¿å ¥ãåé€ãããã³æŽæ°æäœäžã«æå®ããå¿ èŠããããŸãã
éçºè ã«ãšã£ãŠæãéèŠã§ãªãæåŸã®ããããã£ã¯ããããã£ã§ããã¿ã€ã ã¹ã¿ã³ãã¯ããµãŒãã¹ã®å éšããŒãºã察象ãšããŠããããšã³ãã£ãã£ã®æçµå€æŽæå»ã«é¢ããæ å ±ãä¿åããŸãã
äžèšã®ããã«ãããŒãã«ã¹ãã¬ãŒãžã®ããŒã¿ã«ã¢ã¯ã»ã¹ããããã®REST APIããããŸãããMicrosoftã¯ADO.NET Data ServicesãšåŒã°ããããŒã¿ã«ã¢ã¯ã»ã¹ããããã®ç¹å¥ãªã©ã€ãã©ãªãæäŸããŸãïŒãã¬ãŒã ã¯ãŒã¯4.0ã®ææ°ããŒãžã§ã³ã§ã¯ãWCF Data Servicesã«ååãå€æŽãããŸããïŒã ãã®ã©ã€ãã©ãªã¯ãããŒã¿ã¹ããŒã ããšã³ãã£ãã£ãããã³ãããã®ããããã£ãæäœããããã®ã¯ã©ã¹ãéçºè ã«æäŸããŸãã Windows AzureããŒã¿ãµãŒãã¹çšã®ã¯ã©ã€ã¢ã³ããäœæããäŸã䜿çšããŠããã®äœ¿çšæ¹æ³ã以äžã«ç€ºããŸãã
ãã¹ãããŒã¿ã¢ãã«ã®äœæ
æåã®æè¡ããŒã¿ãæºåããããAzure Table Serviceã®ãã¢ããŒã¿ã¢ãã«ã®äœæã«é²ãããšãã§ããŸãã ããããæåã«ãã¯ã©ã€ã¢ã³ãã¢ããªã±ãŒã·ã§ã³ããã¹ãããã³äœæããããã®ç°å¢ãæºåããå¿ èŠããããŸãã ãããè¡ãã«ã¯ãVisual Studioããã³Windows Azure SDKã®ã¢ããªã³ãããŠã³ããŒãããŠã€ã³ã¹ããŒã«ããå¿ èŠããããŸããhttp ïŒ //www.microsoft.com/downloads/details.aspxïŒ FamilyID = 5664019e-6860-4c33-9843-4eb40b297ab6ïŒdisplaylang = en
ãã®åŸãããã°ã©ãã³ã°ã«çŽæ¥é²ãããšãã§ããŸãã ãããè¡ãã«ã¯ãVisual Studio 2010ã§TableServiceExampleãšããåçŽãªã³ã³ãœãŒã«ã¢ããªã±ãŒã·ã§ã³ãäœæããŸãã
System.Data.Services.ClientãMicrosoft.WindowsAzure.StorageClientã¢ã»ã³ããªãžã®ãªã³ã¯ãè¿œå ããŸãã
次ã«ãå®è£ äºå®ã®å£°ãåºãçªã§ããã€ãŸãã2ã€ã®ãšã³ãã£ãã£ã®ã¹ãã¬ãŒãžãäœæããå¿ èŠããããŸãã
- 補åã«ã¯ãååããã©ã³ããäŸ¡æ Œã補åã«ããŽãªãžã®ãªã³ã¯ã®ãã£ãŒã«ããå«ãŸããŠããå¿ èŠããããŸãã
- 補åã«ããŽãªã«ã¯ãã«ããŽãªèå¥åãååã®ãã£ãŒã«ããå«ãŸããŠããå¿ èŠããããŸãã
ããŒã¿ãã¢ããªã±ãŒã·ã§ã³ãªããžã§ã¯ãã«ãããã³ã°ããã«ã¯ãTableServiceEntityããç¶æ¿ããåŸã察å¿ããã¯ã©ã¹ãäœæããå¿ èŠããããŸãã äœæããããªããžã§ã¯ãã«é¢é£ããããã€ãã®åŽé¢ãç¹å®ãããã ãã§ãã1ïŒãã¹ãŠã®è£œåãšã³ãã£ãã£ã¯1ã€ã®ã»ã¯ã·ã§ã³ïŒPartitionKeyïŒã«ãProductPartitionããšããååã§ä¿åããããProductKindPartitionãã»ã¯ã·ã§ã³ã®ãšã³ãã£ãã£ã衚瀺ããŸãã2ïŒRowKeyèå¥åã¯ãäœææã«æå®ãããGuidãªããžã§ã¯ãã
ã補åãã¯ã©ã¹ã®ãœãŒã¹ã³ãŒãïŒ
public class Product : TableServiceEntity
{
public const string PartitionName = "ProductPartition" ;
public Product()
{
}
private Product( string partitionKey, string rowKey)
: base (partitionKey, rowKey)
{
}
public static Product Create()
{
string rowKey = Guid .NewGuid().ToString();
return new Product(PartitionName, rowKey);
}
public string Name { get ; set ; }
public string Trademark { get ; set ; }
public int Kind { get ; set ; }
}
* This source code was highlighted with Source Code Highlighter .
ã補åã¿ã€ããã¯ã©ã¹ã®ãœãŒã¹ã³ãŒãïŒ
public class ProductKind : TableServiceEntity
{
public const string PartitionName = "ProductKindPartition" ;
public ProductKind()
{
}
private ProductKind( string partitionKey, string rowKey)
: base (partitionKey, rowKey)
{
}
public static ProductKind Create()
{
string rowKey = Guid .NewGuid().ToString();
return new ProductKind(PartitionName, rowKey);
}
public int Id { get ; set ; }
public string Name { get ; set ; }
}
* This source code was highlighted with Source Code Highlighter .
äžèšã®ãšã³ãã£ãã£ãä¿åããããã«å¿ èŠãªããŒãã«ãäœæããã«ã¯ã次ã®åºæºã§ããŒã¿ã³ã³ããã¹ãã決å®ããå¿ èŠããããŸãã
1ïŒã³ã³ããã¹ãã¯ã©ã¹ã¯ãTableServiceContextããç¶æ¿ããå¿ èŠããããŸã
2ïŒããŒãã«ããšã«ãIQueryableåã®ããããã£ãå®çŸ©ããå¿ èŠããããŸããDataItemTypeã¯ãããŒãã«ã«æ ŒçŽããããšã³ãã£ãã£ã®åã§ãã
ããŒã¿ã³ã³ããã¹ãã®ãœãŒã¹ã³ãŒããèŠãŠãã ããã
public class TestServiceDataContext : TableServiceContext
{
public TestServiceDataContext( string baseAddress, StorageCredentials credentials)
: base (baseAddress, credentials)
{
}
public const string ProductTableName = "Product" ;
public const string ProductKindTableName = "ProductKind" ;
public IQueryable<Product> Product
{
get { return CreateQuery<Product>( ProductTableName ); }
}
public IQueryable<ProductKind> ProductKind
{
get { return CreateQuery<ProductKind>( ProductKindTableName ); }
}
}
* This source code was highlighted with Source Code Highlighter .
ããŒã¿ã¹ããŒã ãããŒãã«ãµãŒãã¹ã«å±éããåã«ãWindows AzureããŒã¿ãµãŒãã¹èªèšŒã®ååãç解ããå¿ èŠããããŸãã
ããŒãã«ãµãŒãã¹ãžã®ã¢ã¯ã»ã¹ã®èšå®
AzureããŒãã«ããŒã¿ãµãŒãã¹ãžã®åãªã¯ãšã¹ãã¯èªèšŒãããå¿ èŠããããŸããå®éã«ã¯ãããã¯åREST APIãªã¯ãšã¹ãã«ç¹å¥ã«åœ¢æããã眲åãå«ãŸããããšãæå³ããŸãã 詳现ã«ã€ããŠã¯èª¬æããŸããããSDKã®å¯Ÿå¿ããã»ã¯ã·ã§ã³ãèªãããšãèå³æ·±ãå Žåã¯ãAzure Storageã®ADO .NETããŒã¿ãµãŒãã¹ããã¹ãŠã®å€§éæãªäœæ¥ãè¡ããããèªèšŒããŒã¿ãæ£ããæå®ããã ãã§æžã¿ãŸãã ãã®ãããªããŒã¿ã¯ãã¢ã«ãŠã³ãåïŒã¢ã«ãŠã³ãïŒãšã¢ã¯ã»ã¹ããŒïŒå ±æããŒïŒã§ãã
äœæããŠããããã°ã©ã ã«äœããè¿œå ããåã«ãã³ã³ãã¥ãŒã¿ãŒã§ããŒã«ã«ã¹ãã¬ãŒãžãšãã¥ã¬ãŒã¿ãŒãå®è¡ããå¿ èŠããããŸããããã«ãExpressãå«ããã¹ãŠã®ãšãã£ã·ã§ã³ã®SQL Serverãã€ã³ã¹ããŒã«ãããŠããå¿ èŠãããããšãäºçŽããå¿ èŠããããŸãã ãã®ããã°ã©ã ã¯Windows Azure SDKã«å«ãŸããŠããããã®ååã¯Development Storageã§ãã æåã®èµ·åã®åã«ãã¢ããªã±ãŒã·ã§ã³ã¯ããŒã¿ããŒã¹ãäœæããŠéå§ããŸããããŒã¿ããŒã¹ã¯åŸã§æ å ±ãä¿åããããã«äœ¿çšããŸãã ãã¹ãŠãããŸããããšãéç¥é åã«éçºã¹ãã¬ãŒãžã¢ã€ã³ã³ã衚瀺ããããããã¯ãªãã¯ãããšãçŸåšå®è¡äžã®ãµãŒãã¹ãšãã®ããŒã«ã«ã¢ãã¬ã¹ã確èªã§ããŸãã
ãããã®èªèšŒã¯ãæ¢ç¥ã®äºåçæããŒã¿ã«åŸã£ãŠè¡ãããŸãã
- ã¢ã«ãŠã³ãåïŒdevstoreaccount1
- ã¢ã«ãŠã³ãããŒïŒEby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq / K1SZFPTOtr / KBHBeksoGMGw ==
ã¢ããªã±ãŒã·ã§ã³ã§äœ¿çšããã®ã¯ãã®æ å ±ã§ãã ãŸããæ§æãã¡ã€ã«App.configãè¿œå ãã次ã®è¡ãappSettingsã»ã¯ã·ã§ã³ã«æžã蟌ã¿ãŸãã
< configuration >
< appSettings >
< add key ="AccountName" value ="devstoreaccount1" />
< add key ="AccountSharedKey" value ="Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==" />
< add key ="TableStorageEndpoint" value ="http://127.0.0.1:10002/devstoreaccount1" />
</ appSettings >
</ configuration >
* This source code was highlighted with Source Code Highlighter .
次ã«ãã³ãŒããé©åã«ãã©ãŒãããããããã«ãTableStoreManagerã¯ã©ã¹ãäœæãã次ã®ãã£ãŒã«ããè¿œå ããŸãã
- StorageCredentialsAccountAndKeyã¿ã€ãã®_credentials-å ±æããŒïŒå ±æããŒïŒã®èªèšŒã¹ããŒã ãä»ãããããŒãã«ã¹ãã¬ãŒãžïŒããŒãã«ã¹ãã¬ãŒãžïŒãžã®ã¢ã¯ã»ã¹ã«é¢ããããŒã¿ãè¡šããŸã
- ã¿ã€ãCloudTableClientã®_tableStorage-ã¯ãªãã¯ããŠããŒãã«ã¹ãã¬ãŒãžã«ã¢ã¯ã»ã¹ããŸãã
- TestServiceDataContextåã®_context-åã®ã»ã¯ã·ã§ã³ã§äœæãããã¯ã©ã¹ã§ããã¹ãŠã®ããŒãã«ã®èª¬æãå«ãŸããŸãã
次ã«ãèšè¿°ãããTableStoreManagerã®ã¿ã€ãã§ã¯ãããããã¹ãŠã®ãã£ãŒã«ãã次ã®è¡ã§åæåããå¿ èŠããããŸãã
string accountKey = ConfigurationManager .AppSettings[ "AccountSharedKey" ];
string tableBaseUri = ConfigurationManager .AppSettings[ "TableStorageEndpoint" ];
string accountName = ConfigurationManager .AppSettings[ "AccountName" ];
_credentials = new StorageCredentialsAccountAndKey(accountName, accountKey);
_tableStorage = new CloudTableClient(tableBaseUri, _credentials);
_context = new TestServiceDataContext(tableBaseUri, _credentials);
* This source code was highlighted with Source Code Highlighter .
åæåããããã¹ãŠã®ã¢ã¯ã»ã¹ã³ã³ããŒãã³ããæã£ãã®ã§ãããŒãã«ãäœæããå¿ èŠããããã©ããã確èªããå¿ èŠããããŸãããªããžããªã§äœæããå¿ èŠãããå Žåã¯ãå¥ã®TryCreateSchemaã¡ãœããã§ãããè¡ããŸãã
var list = from table in _tableStorage.ListTables()
where table == TestServiceDataContext.ProductKindTableName
|| table == TestServiceDataContext.ProductTableName select table;
if (list != null && list.ToList< string >().Count == 0){
CloudTableClient.CreateTablesFromModel( typeof (TestServiceDataContext),
ConfigurationManager .AppSettings[ "TableStorageEndpoint" ],
_credentials);
}
* This source code was highlighted with Source Code Highlighter .
ããã§ã¯ããŸããæ¢åã®ããŒãã«ã®ãã¹ãŠã®ããŒãã«ãéžæãããããã®ååãã¹ããŒã å ã®ããŒãã«ãšæ¯èŒããŸããããŒãã«ãèŠã€ãããªãå Žåãããã°ã©ã ã¯TestServiceDataContextã¯ã©ã¹ã§å®çŸ©ããã¢ãã«ã«åŸã£ãŠããŒãã«ãäœæããŸãã æåŸã«ãäœæããã¡ãœããã®åŒã³åºããã以åã«å®çŸ©ããInitializeã¡ãœããã«è¿œå ããå¿ èŠããããŸãã
ã¹ãã¬ãŒãžããããŒã¿ãååŸããŠããŸãã
Azure Table Storageã«ã¯ãã¹ãã¬ãŒãžå ã®ããŒãã«ã«ã¯ãšãªãäœæããããã®ããªãå€æ§ãªAPIããããŸããããšãã°ãç¹å®ã®æ°ã®èŠçŽ ãèŠæ±ããããæåã®èŠçŽ ãè¿ããããç¹å®ã®ãã£ãŒã«ãã§ãã£ã«ã¿ãŒãããã§ããŸãã ãã ããããã§åé¡ã®Storageã®çŸåšã®å®è£ ã«ã¯ããã€ãã®å¶éããããŸãããŸããäžåºŠã«1000ãè¶ ããèŠçŽ ãè¿ãããšã¯ã§ããããããã®å°ãªããšã1ã€ã5ç§ãè¶ ããŠåèŠæ±ãå®è¡ã§ããªããšããäºå®æ¡ä»¶ãæºããããªãå ŽåããµãŒãã¹ã¯ãšã©ãŒãè¿ããŸãã ããããã¯ãšãªã®äœæã«æ»ããšãADO .NET Services Frameworkã¯ããŠã§ã¢ããŠã¹ãµãŒãã¹ã«REST APIã䜿çšããã«ãŒãã³ãç°¡åã«ããã¯ãšãªãã³ã³ãã€ã«ããããã®LINQæ§æããŠãŒã¶ãŒã«æäŸããŸãã æ®å¿µãªãããããŒã¿ã«ã¢ã¯ã»ã¹ããããã®ãã¹ãŠã®LINQæ©èœãçŸåšã®å®è£ ã§ãµããŒããããŠããããã§ã¯ãããŸãããçŸåšã䜿çšã§ããæŒç®åã¯ãããã§ãã
- ãã-å®å šã«ãµããŒã
- ã©ã-å®å šã«ãµããŒã
- ãã€ã¯-æ倧1000åã®èŠçŽ ã§ãµããŒã
- ãŸããFirstOrDefault-å®å šã«ãµããŒããããŠããŸãã
ããã§ãªã¹ãã®çµããã§ãã ã¯ãšãªãã³ã³ãã€ã«ããã«ã¯ãTestServiceDataContext.CreateQueryã¡ãœããã䜿çšããå¿ èŠããããŸããããã§ãTã¯è¿ããããšã³ãã£ãã£ã®ã¿ã€ãã§ãã
å©çšå¯èœãªãã¹ãŠã®è£œåãè¿ãã¡ãœãããäœæããŸãïŒ1000èŠçŽ ã®å¶éã¯ãŸã 確èªããŠããŸããïŒ
public List <Product> GetAllProducts()
{
var products = from product in _context.CreateQuery<Product>(TestServiceDataContext.ProductTableName) select product;
return products.ToList<Product>();
}
* This source code was highlighted with Source Code Highlighter .
次ã«ãå©çšå¯èœãªãã¹ãŠã®ã«ããŽãªã®éžæãšããã®èå¥åã«ããç¹å®ã®ã«ããŽãªãäœæããŸãã
public List <ProductKind> GetProductKinds()
{
var productKinds = from productKind in
_context.CreateQuery<ProductKind>(TestServiceDataContext.ProductKindTableName)
select productKind;
return productKinds.ToList<ProductKind>();
}
public ProductKind GetProductKind( int id)
{
var productKinds = ( from productKind in
_context.CreateQuery<ProductKind>(TestServiceDataContext.ProductKindTableName)
where productKind.Id == id
select productKind);
var productKindList = productKinds.ToList<ProductKind>();
ProductKind result = null ;
if (productKindList.Count > 0) {
result = productKindList[0];
}
return result;
}
* This source code was highlighted with Source Code Highlighter .
ä»ãç§ã¯ãµãŒãã¹ãä»äºã§ãã§ãã¯ããããšæããŸããããããéå§ããŠãã¹ãŠãæ£ããæ©èœããå Žåããªããžããªã«ããŒã¿ããªããããäœã衚瀺ãããŸããããããã£ãŠãæåã®ãã¢ã§ã¯ããšã³ãã£ãã£è¿œå ã¡ã«ããºã ãå®è£ ããå¿ èŠããããŸãã
ã¯ã©ãŠãã«ããŒã¿ãè¿œå ãã
ADO .NETãµãŒãã¹ã䜿çšããŠæ°ãããšã³ãã£ãã£ãè¿œå ããæé ã¯éåžžã«ç°¡åã«èŠããŸããè¿œå ãããšã³ããªãããŒãã«å šäœã§äžæã®RowKeyãšPartiotionKeyãæã£ãŠããããšã確èªããŠãã ããã æ¿å ¥æäœã®å Žåãäœæãããã³ã³ããã¹ãTestServiceDataContext.AddObjectã®ã¡ãœããã«æåã®ãã©ã¡ãŒã¿ãŒãè¿œå ãè¡ãããããŒãã«ã®ååãããã³2çªç®ã®ãã©ã¡ãŒã¿ãŒãè¿œå ãããªããžã§ã¯ãèªäœãæž¡ãå¿ èŠããããŸãã ãã®åŸã2ã€ã®ã¡ãœããïŒDataServiceContext.SaveChangesïŒãåŒã³åºããŠã¯ã©ãŠãã¹ãã¬ãŒãžãžã®æ°ããããŒã¿ã®éä¿¡ã匷å¶ããDataServiceContext.Detach-ã³ã³ããã¹ããããªããžã§ã¯ããžã®ãªã³ã¯ãåé€ããŸãã ãããã£ãŠãTableStoreManagerã¯ã©ã¹ã§ã¯ãProductãšã³ãã£ãã£ãšProductKindãšã³ãã£ãã£ãããããè¿œå ãã2ã€ã®Insertã¡ãœãããäœæããŸãã
public void Insert(Product product)
{
_context.AddObject(TestServiceDataContext.ProductTableName, product);
_context.SaveChanges();
_context.Detach(product);
}
public void Insert(ProductKind productKind)
{
_context.AddObject(TestServiceDataContext.ProductKindTableName, productKind);
_context.SaveChanges();
_context.Detach(productKind);
}
* This source code was highlighted with Source Code Highlighter .
æåã®ãµãŒãã¹ãã¹ã
Azure Table Storageã®ã¢ãŒããã¯ãã£ã«é·ãé觊ããåŸããã®ãµãŒãã¹ã®åäœã確èªã§ããŸãããã®ãããã³ã³ãœãŒã«ããã°ã©ã ã®Mainã¡ãœããã«æ¬¡ã®è¡ãèšè¿°ããŸãã
try
{
TableStoreManager manager = new TableStoreManager();
manager.Initialize();
ProductKind productKind = ProductKind.Create();
productKind.Name = "" ;
productKind.Id = 1;
manager.Insert(productKind);
Product product = Product.Create();
product.Name = "" ;
product.Kind = productKind.Id;
product.Trademark = "Candy" ;
manager.Insert(product);
}
catch (Exception ex)
{
Console .WriteLine(ex.Message);
}
* This source code was highlighted with Source Code Highlighter .
ãã®ããã°ã©ã ã§ã¯ããŸãããŒãã«ãµãŒãã¹æ§é ãåæåããããã«å¿ èŠãªããŒãã«ãäœæãã次ã«ããGoodsãããŒãã«ãšãTypes of GoodsãããŒãã«ã«1ã€ã®ã¬ã³ãŒããè¿œå ããŸãã ããã§ããã¹ãããåã«ãããŒã«ã«ã®ãã¯ã©ãŠããDevelopmentStorageãèµ·åããŠããã°ã©ã ãå®è¡ããããšãå¿ããªãã§ãã ããã ãã¹ãŠãæ£ããæžã蟌ãŸããå®è¡ãããå Žåãããã°ã©ã ã¯æ°ç§åŸ æ©ããåäžãšã©ãŒãªãã§å¶åŸ¡ãè¿ããŸãã 次ã«ãããŒã¿ãå®éã«ããŒã«ã«ã¹ãã¬ãŒãžã«ä¿åãããŠããããšã確èªããå¿ èŠããããŸãããã®ããã«ãMainã¡ãœãããå€æŽããŸãã
try
{
TableStoreManager manager = new TableStoreManager();
manager.Initialize();
var products = manager.GetAllProducts();
foreach (Product product in products)
{
Console .WriteLine( ": {0} {1}" , product.Name, product.Trademark);
ProductKind productKind = manager.GetProductKind(product.Kind);
if (productKind != null )
{
Console .WriteLine( " : {0}" , productKind.Name);
}
}
}
catch (Exception ex)
{
Console .WriteLine(ex.Message);
}
* This source code was highlighted with Source Code Highlighter .
DevelopmentStorageãå¿ããã«ããã°ã©ã ãããäžåºŠå®è¡ããŠã¿ãŸãããããã¹ãŠãæ£ããå Žåãã³ã³ãœãŒã«ã§ä¿åããããã¹ãŠã®ããŒã¿ãè¿ãããåŠçã®æºåãã§ããŠããããšãããããŸãã
ãšã³ãã£ãã£ã®æŽæ°
ããŒãã«ã¹ãã¬ãŒãžå ã®ãšã³ãã£ãã£ãæŽæ°ããã¡ã«ããºã ã¯ãå€æŽãããªããžã§ã¯ãã®RowKeyå€ãšPatitionKeyå€ãæå®ããå¿ èŠããããã³ã«éåžžã«ç°¡åã§ãã ãšã³ãã£ãã£ãžã®ç«¶äºåã®ããã¢ã¯ã»ã¹ã確ä¿ããããã«ãå¿ é ãã©ã°EtagïŒREST APIã®If-MatchããããŒïŒãå°å ¥ãããŸããã ãã®ãã©ã°ã¯ããã®ãªããžã§ã¯ããŸãã¯ãã®ãªããžã§ã¯ãããã€å€æŽããããã決å®ãããã®Etagãæ¢åã®ã¹ãã¬ãŒãžãšäžèŽããªãå ŽåãããŒã¿ã®å€æŽãèš±å¯ãããæ å ±ããªã»ããããå¿ èŠãããããšãç¥ããããšã©ãŒãè¿ããŸãã ãã ããETagã§*èšå·ãèšå®ããããšã«ãããç¡æ¡ä»¶ã®æŽæ°ã«ç¬ç«ããŠåœ±é¿ãäžããããšãã§ããŸãã
Ado .Net Data Servicesãä»ããŠãªããžã§ã¯ããæŽæ°ããã«ã¯ãæåã«TableServiceContext.AttachToã¡ãœããã䜿çšããŠãªããžã§ã¯ããã³ã³ããã¹ãã«è¿œå ãã次ã«åããªããžã§ã¯ããTableServiceContext.UpdateObjectã¡ãœããã«æž¡ããŠåŒã³åºããTableServiceContext.SaveChangesã¡ãœãããåŒã³åºããŠãµãŒããŒã«æ å ±ãéä¿¡ããå¿ èŠããããŸãïŒ
public void Update(Product product)
{
_context.Detach(product);
_context.AttachTo(TestServiceDataContext.ProductTableName, product, "*" );
_context.UpdateObject(product);
_context.SaveChanges();
}
* This source code was highlighted with Source Code Highlighter .
æåã«ãæŽæ°ããåã«ãæŽæ°ããããªããžã§ã¯ããAdo .NETãµãŒãã¹ã®èŠèŠãã£ãŒã«ãã«ãªãããšã確èªããå¿ èŠããããŸãããã®ããã«ãTableServiceContext.Detachã¡ãœãããåŒã³åºããŸãã
ããã§ãå°ããªãã¹ããäœæããŠããã¹ãŠãæ©èœããããšã確èªã§ããŸãã
TableStoreManager manager = new TableStoreManager();
manager.Initialize();
var products = manager.GetAllProducts();
foreach (Product product in products)
{
product.Name += " 2" ;
product.Trademark = "" ;
manager.Update(product);
}
products = manager.GetAllProducts();
foreach (Product product in products)
{
Console .WriteLine(product.Name);
* This source code was highlighted with Source Code Highlighter .
èšè¿°ãããã³ãŒããå®è¡ãããšãããŒã¿ãæ£åžžã«å€æŽãããäœæãããããã·ãŒãžã£ã®ãã¹ããå®äºãããšèŠãªãããšãã§ããŸãã
ãšã³ãã£ãã£ã®åé€ã
æŽæ°ãšåæ§ã«ããªããžã§ã¯ãã®åé€ã«ã¯2ã€ã®ããããã£ãå¿ èŠã§ãããããã¯RowKeyãšPartitionKeyã§ãããEtagãã©ã°ã®æå®ãå«ã¿ãŸãããã®åäœã¯åã®ã»ã¯ã·ã§ã³ã§èª¬æãããã®ãšäŒŒãŠããŸãã å®éããšã³ãã£ãã£ã¯åé€ããããšãåé€æžã¿ããšããŠããŒã¯ãããã¯ã©ã€ã¢ã³ãããã¢ã¯ã»ã¹ã§ããªããªããå®æçãªã¬ããŒãžã³ã¬ã¯ã·ã§ã³ãçºçãããšç©ççã«åé€ãããŸãã ADO .NETãµãŒãã¹ã䜿çšããŠ-Productãšã³ãã£ãã£ãåé€ããã³ãŒãã以äžã«ç€ºããŸãã
public void Delete(Product product)
{
_context.Detach(product);
_context.AttachTo(TestServiceDataContext.ProductTableName, product, "*" );
_context.DeleteObject(product);
_context.SaveChanges();
}
* This source code was highlighted with Source Code Highlighter .
æ£ããæäœããã¹ãããããã«ãMainã¡ãœããã«æ¬¡ã®è¡ãèšè¿°ã§ããŸãã
TableStoreManager manager = new TableStoreManager();
manager.Initialize();
var products = manager.GetAllProducts();
foreach (Product product in products)
{
Console .WriteLine( ": {0} {1}" , product.Name, product.Trademark);
manager.Delete(product);
}
products = manager.GetAllProducts();
if (products.ToArray().Length == 0)
{
Console .WriteLine( " " );
}
* This source code was highlighted with Source Code Highlighter .
ãããã«
ãã®èšäºã§ã¯ãã¯ã©ãŠããµãŒãã¹ã®ããããã®ã¿ã€ãã«ã¢ã¯ã»ã¹ããããã®äžè¬çãªã¢ãããŒãã瀺ããŸããã Ado .NET Servicesã©ã€ãã©ãªã«ã¯ãå¥ã®èšäºãæžãããšãã§ããèå³æ·±ããã¥ã¢ã³ã¹ãããããããã®ã§ãè¿œå ã®æ¡ä»¶ã§ã³ãŒãã«è² æ ããããªãããã«ããŸããããã§ããã ã軜ãããŸããã
æ®å¿µãªãããçŸåšãã·ã¢ã®æ¶è²»è ã¯æ¬æ ŒçãªããŒãžã§ã³ã®Azureãã©ãããã©ãŒã ãå©çšã§ããªããããèšè¿°ãããäŸããã¹ãããããšã¯ã§ããŸããã ãã ããèè ã¯2009幎ã®æ¥ããCTPãžã®æåŸ ã®ææè ã§ãããå®éã®ã¯ã©ãŠãäžã§Azureã«ç²Ÿéããããã«äžå®éïŒå¶éä»ãïŒã®ãµãŒãã¹ãäœæããæš©å©ãäžããŠããŸãã ãã®ç¹ã§ãçŽ1幎åãããã³ã¹ãããã§å®è¡ãããŠããã¯ã©ãŠããµãŒãã¹ãäœæããããšã§ããã®ã¢ãããŒãã1幎åã«ãã¹ãããŸããïŒ2009幎6æã«éå§ãããŸããïŒã
PS
ãœãŒã¹ã¯ããããããŠã³ããŒãã§ããŸã