Coder Social home page Coder Social logo

patryk / windowsazure Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dtretyakov/windowsazure

0.0 1.0 0.0 64 KB

.NET library aimed at managing and querying entities from Windows Azure Storage. It can be used as LINQ to Azure Tables.

License: MIT License

windowsazure's Introduction

Windows Azure Storage Extensions

Windows Azure Storage Extensions is a .NET library aimed at managing and querying entities from Windows Azure Storage Tables.

It's built on top of the Windows Azure Storage Client Library 2.0, provides async interfaces (Task-based Asynchronous Pattern) and LINQ to Azure Table queries via TableSet context by using POCO entities.

Latest project build:

Table Of Contents

Features

###POCO Objects

Entity's properties and fields should be marked by one or both of PartitionKey and RowKey attributes for defining composite table key. Also can be used Timestamp, ETag, Property and Ignore attributes.

###Entities Management

Generic TableSet context provides a synchronous & asynchronous (TAP) methods for managing entities:

  • Synchronous: Add, AddOrUpdate, Update and Remove.
  • Asynchronous: AddAsync, AddOrUpdateAsync, UpdateAsync and RemoveAsync.

To avoid restrictions of group operations in Azure Storage all entities sorted by partition keys and merged into groups by 100 entities. Execution of requests with such batch operations can be configured via TableSet's ExecutionMode property. Allowed values:

  • Sequential
  • Parallel

Default ExecutionMode is Sequential.

###LINQ Queries

TableSet context implements IQueryable interface for using LINQ Expressions. Provider supports next synchronous LINQ methods:

  • First
  • FirstOrDefault
  • Single
  • SingleOrDefault
  • Take
  • Where

To utilize filtering capabilities of string properties it supports:

Also you can use Contains method. In this case query statement for each collection's item will be joined by using OData or operator.

NOTE: For creating a custom queries you should take a look at next article: Mixing LINQ Providers and LINQ to Objects.

###Asynchronous LINQ Queries

In addition TableSet can be used for asynchronous queries powered by LINQ extensions (TAP) in EF 6 Async style.

Available methods:

  • FirstAsync
  • FirstOrDefaultAsync
  • SingleAsync
  • SingleOrDefaultAsync
  • TakeAsync
  • ToListAsync

###LINQ Projections

LINQ Projections supported with a limitation - projection class should be a reference type.

###TAP-based Extensions

Library contains TAP-based extensions for following Azure Storage Library classes:

  • CloudBlobClient
  • CloudBlobContainer
  • CloudTableClient
  • CloudTable

To use it just add Async postfix to synchronous method name for instance:

blobs = cloudBlobContainer.ListBlobs();
blobs = await cloudBlobContainer.ListBlobsAsync();

###Task Cancellation

All of TAP-based methods accepts optional CancellationToken parameter for Task Cancellation.

Download

Via NuGet

To install library by using Windows Azure Storage Extensions nuget package execute next command:

Install-Package WindowsAzure.StorageExtensions

Via Git

To get the source code of the library via git just type:

git clone git://github.com/dtretyakov/WindowsAzure.git
cd ./WindowsAzure

Dependencies

Storage Extensions requires .NET Framework 4.0 or higher and WindowsAzure.Storage nuget package.

Code Samples

  • Declaring a new POCO class:
public sealed class Country
{
    [PartitionKey]
    public string Continent { get; set; }
    [RowKey]
    public string Name { get; set; }
    public long Population { get; set; }
    public double Area { get; set; }
    public DateTime Formed { get; set; }
}
  • Creating a new table context:
var storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
var tableClient = storageAccount.CreateCloudTableClient();

var countryTable = new TableSet<Country>(tableClient);
  • Adding a new entity:
var resultSync = countryTable.Add(country);
var resultAsync = await countryTable.AddAsync(country);
  • Updating an entity:
resultSync.Area += 333333;
resultSync = countryTable.Update(resultSync);

resultAsync.Population *= 2;
resultAsync = await countryTable.UpdateAsync(resultAsync);
  • Removing entities:
countryTable.Remove(resultSync);
await countryTable.RemoveAsync(resultAsync);
  • Querying entities:
var query = countryTable.Where(
        p => p.Formed > new DateTime(1950, 1, 1) &&
             (p.PresidentsCount < 10 ||
              p.Population < 10000000 && p.PresidentsCount > 10 && p.IsExists));

resultsSync = query.ToList();
resultsAsync = await query.ToListAsync();
  • Using LINQ projections:
var projection = from country in countryTable
                 where country.Area > 400000
                 select new { country.Continent, country.Name };

var result = projection.ToList();
result = await projection.ToListAsync();
  • Using Contains in the LINQ query:
var countryNames = new List<string> { "Germany", "Finland" };
var countries = countryTable.Where(p => countryNames.Contains(p.Name)).ToList();

Sponsors

windowsazure's People

Contributors

dtretyakov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.