Skopiuj wszystkie wiersze do innej tabeli w magazynie tabel Azure
Jak najlepiej skopiować wszystkie wiersze z jednej tabeli do innej?
Próbowałem poniżej kodu, aby uzyskać wszystkie wiersze w tabeli:
TableServiceContext _dataContext;
public IEnumerable<T> GetAllEntities()
{
IQueryable<T> query = null;
try
{
query = _dataContext.CreateQuery<T>(_tableName);
}
catch (Exception ex)
{
}
return query.ToArray();
}
ale nie pobiera wierszy więcej niż około 900. Mam kilkaset tysięcy wierszy.
Zaktualizowany kod:
public class TableRepository<T> : IRepository<T>
where T : TableEntity
{
protected readonly string _tableName;
protected readonly TableServiceContext _dataContext;
protected readonly CloudTable _tableReference;
public TableRepository(string tableName, CloudTableClient tableClient)
{
_tableName = tableName;
_dataContext = tableClient.GetTableServiceContext();
_tableReference = tableClient.GetTableReference(tableName);
_dataContext.ResolveType = ResolveEntityType;
_dataContext.MergeOption = System.Data.Services.Client.MergeOption.NoTracking;
}
public IEnumerable<T> GetAllEntities()
{
List<T> allEntities = new List<T>();
try
{
Microsoft.WindowsAzure.Storage.Table.TableContinuationToken tableContinuationToken = null;
do
{
var queryResponse = _tableReference.ExecuteQuerySegmented<T>(null, tableContinuationToken, null, null);
tableContinuationToken = queryResponse.ContinuationToken;
allEntities.AddRange(queryResponse.Results);
}
while (tableContinuationToken != null);
}
catch (Exception ex)
{
throw new DALException(_tableName,_dataContext.BaseUri.OriginalString, "An error occured while querying data", ex);
}
return allEntities;
}
}
ale z błędem:
Błąd 121 „T” musi być typem nie-abstrakcyjnym z publicznym konstruktorem bez parametrów w celu użycia go jako parametru „TElement” w typie ogólnym lub metodzie „Microsoft.WindowsAzure.Storage.Table.CloudTable.ExecuteQuerySegmented”