/// <summary> /// Creates tables from a DataServiceContext derived class. /// </summary> /// <param name="serviceContextType">A DataServiceContext derived class that defines the table schemas.</param> /// <param name="baseAddress">The baseAddress of the table storage endpoint.</param> /// <param name="credentials">Storage account credentials.</param> /// <remarks> /// For each table, the class exposes one or more IQueryable<T> properties, where T is a /// TableServiceEntity derived class with the required schema. /// </remarks> public static void CreateTablesFromModel(Type serviceContextType, string baseAddress, StorageCredentials credentials) { CloudTableClient.CreateTablesFromModel(serviceContextType, baseAddress, credentials); CloudTableClient tableStorage = new CloudTableClient(baseAddress, credentials); // Execute conditionally for development storage only if (tableStorage.BaseUri.IsLoopback) { var properties = serviceContextType.GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (var table in properties.Where(p => p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(IQueryable <>))) { TableServiceEntity entity = Activator.CreateInstance(table.PropertyType.GetGenericArguments()[0]) as TableServiceEntity; if (entity != null) { InitializeTableSchemaFromEntity(tableStorage, table.Name, entity); } } } }