Скопируйте все строки в другую таблицу в хранилище таблиц Azure.
Каков наилучший способ скопировать все строки из одной таблицы в другую таблицу?
Я попробовал код ниже, чтобы получить все строки в таблице:
TableServiceContext _dataContext;
public IEnumerable<T> GetAllEntities()
{
IQueryable<T> query = null;
try
{
query = _dataContext.CreateQuery<T>(_tableName);
}
catch (Exception ex)
{
}
return query.ToArray();
}
но он не получает строк больше, чем около 900. У меня есть несколько сотен тысяч строк.
Обновленный код:
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;
}
}
но с ошибкой:
Ошибка 121 «T» должна быть неабстрактного типа с открытым конструктором без параметров, чтобы использовать его в качестве параметра «TElement» в универсальном типе или методе «Microsoft.WindowsAzure.Storage.Table.CloudTable.ExecuteQuerySegmented