项目作者: chaowlert

项目描述 :
Extensions for Azure Storage Client library
高级语言: C#
项目地址: git://github.com/chaowlert/AzureStorageExtensions.git
创建时间: 2014-12-20T13:19:14Z
项目社区:https://github.com/chaowlert/AzureStorageExtensions

开源协议:MIT License

下载


AzureStorageExtensions

Extensions for Azure Storage Client library

NuGet

Get it

  1. PM> Install-Package AzureStorageExtensions

Basic usage

1. Context

Create Context is easy, just inherit from BaseCloudContext and declear property any types of CloudQueue, CloudBlobContainer, CloudTable, and new generic CloudTable<T>

  1. public class MyContext : BaseCloudContext
  2. {
  3. public MyContext(string connectionString) : base(connectionString) { }
  4. public CloudQueue MyQueue { get; set; }
  5. public CloudBlobContainer MyBlob { get; set; }
  6. public CloudTable<MyClass> MyTable { get; set; }
  7. }

2. CloudTable

The new generic CloudTable allow you to create, retrieve, update, replace, merge, delete, query, and bulk opertations much easier.

  1. var person = await context.Person.RetrieveAsync(partitionKey, rowKey);
  2. await context.Persons.InsertAsync(newPerson);
  3. await context.Persons.InsertOrReplaceAsync(newPerson);
  4. await context.Persons.InsertOrMergeAsync(partialPerson);
  5. await context.Persons.UpdateAsync(person);
  6. await context.Persons.ReplaceAsync(person);
  7. await context.Persons.MergeAsync(partialPerson);
  8. await context.Persons.DeleteAsync(person);
  9. //bulk also support for all operations
  10. await context.Persons.BulkInsertAsync(persons);
  11. //async query also support (required System.Linq.Async)
  12. var children = await (from p in context.Persons.Query()
  13. where p.Age <= 18
  14. select p)
  15. .AsAsyncTableQuery()
  16. .ToListAsync();

3. Archive Table

Table (also blob container and queue) can be parition by time. This is suitable for log or temporary data. Just add setting attribute to property in context.

  1. public class MyContext : BaseCloudContext
  2. {
  3. [Setting(Period=Period.Month)]
  4. public CloudTable<Log> Logs { get; set; }
  5. }

When new logs insert to table it will be kept based on time.
Log201410
Log201411
Log201412

4. Expandable Table Entity

Azure table limits each property to 64k, but ExpandableTableEntity allows you to keep data up to 1M limit.

  1. public class Log : ExpandableTableEntity
  2. {
  3. public string Message { get; set; } //this message can be up to 1M
  4. }

Migrate from 1.x

AzureStorageExtensions is no more depending on Web.Config. You can add constructor and read connection string.

  1. public class MyContext : BaseCloudContext
  2. {
  3. public MyContext()
  4. : base(ConfigurationManager.ConnectionStrings[nameof(MyContext)].ConnectionString) { }
  5. }