dtretyakov / WindowsAzure

.NET library aimed at managing and querying entities from Windows Azure Storage. It can be used as LINQ to Azure Tables.
MIT License
64 stars 27 forks source link

No happy-path for creating a table if it doesn't exist. #41

Closed tdietrich513 closed 9 years ago

tdietrich513 commented 9 years ago

It would be nice to have exposed methods to create storage tables when they don't already exist, or at least get a TableReference to the table being managed by the TableSet<T> so that the standard methods can be used.

It seems like it should be easy enough to store the CloudTable reference generated in the TableSet constructor as a class member rather than having it be a local variable and expose that- if that approach works for you I can submit a pull request.

dtretyakov commented 9 years ago

Hi Tom,

Nice idea to add such feature. So it would be great if you extend ITableSet interface and add a new method a la CreateIfNotExists. Waiting for your PR.

tdietrich513 commented 9 years ago

Just submitted a very simple pull request which just exposes the CloudTable via a Table() method on the TableSet. Using this you could do tableSet.Table().CreateIfNotExists().

dtretyakov commented 9 years ago

Unfortunately such implementation exposes types from Azure .NET SDK library, but ITableSet should use only abstract data types. So it's better to just add pair of methods CreateIfNotExists / CreateIfNotExistsAsync in the interface like that:

private readonly CloudTable _cloudTable;
public TableSet(CloudTableClient cloudTableClient, string tableName)
{
    ...
    _cloudTable = cloudTableClient.GetTableReference(tableName);
    ...
}
public bool CreateIfNotExists()
{
    _cloudTable.CreateIfNotExists();
}
public Task<bool> CreateIfNotExistsAsync()
{
    _cloudTable.CreateIfNotExistsAsync();
}
tdietrich513 commented 9 years ago

I was considering taking that approach, but it seems like it opens Pandora's box of other CloudTable methods that might be desired, such as deleting the table if appropriate. But I'll yield to you on that design point. Submitting that pull request in a minute.

dtretyakov commented 9 years ago

Thanks, it was published: https://www.nuget.org/packages/WindowsAzure.StorageExtensions/

tdietrich513 commented 9 years ago

Thanks!