Closed tdietrich513 closed 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.
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()
.
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();
}
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.
Thanks, it was published: https://www.nuget.org/packages/WindowsAzure.StorageExtensions/
Thanks!
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 theTableSet<T>
so that the standard methods can be used.It seems like it should be easy enough to store the
CloudTable
reference generated in theTableSet
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.