2013-08-22 7 views
5

सभी पंक्तियों को एक तालिका से दूसरी तालिका में कॉपी करने का सबसे अच्छा तरीका क्या है?
मैं किसी तालिका में सभी पंक्तियां प्राप्त करने कोड के नीचे की कोशिश की: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; 
    } 

}

लेकिन त्रुटि के साथ:

Error 121 'T' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'TElement' in the generic type or method 'Microsoft.WindowsAzure.Storage.Table.CloudTable.ExecuteQuerySegmented

उत्तर

7

कारण आप केवल 900 परिणामों को वापस हो रही है है, क्योंकि आप निरंतरता टोकन में चला रहे हैं। डिफ़ॉल्ट रूप से टेबल सेवा के लिए एक ही अनुरोध अधिकतम 1000 इकाइयों को वापस कर देगा। यह 1000 से कम इकाइयों (और यहां तक ​​कि 0) से भी कम हो सकता है लेकिन 1000 से अधिक नहीं। यदि अधिक इकाइयां उपलब्ध हैं, तो तालिका सेवा continuation token लौटाती है जिसका उपयोग अगले इकाइयों को लाने के लिए किया जाना चाहिए।

तो आपके कोड को निरंतर टोकन की तलाश करनी चाहिए और जब तक टेबल सेवा द्वारा टोकन वापस नहीं किया जाता है तब तक संस्थाओं को लाने पर ध्यान देना चाहिए। नीचे नमूना कोड पर एक नज़र है:

private IEnumerable<T> FetchAllEntities() 
{ 
    List<T> allEntities = new List<T>(); 
    CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount; 
    CloudTable table = storageAccount.CreateCloudTableClient().GetTableReference("MyTable"); 
    Microsoft.WindowsAzure.Storage.Table.TableContinuationToken tableContinuationToken = null; 
    do 
    { 
     var queryResponse = table.ExecuteQuerySegmented<T>(null, tableContinuationToken, null, null); 
     tableContinuationToken = queryResponse.ContinuationToken; 
     allEntities.AddRange(queryResponse.Results); 
    } 
    while (tableContinuationToken != null); 
    return allEntities; 
} 

अद्यतन

अपने त्रुटि के लिए, इसके अलावा बदलते निम्नलिखित

public class TableRepository<T> : IRepository<T> 
    where T : TableEntity 

public class TableRepository<T> : IRepository<T> 
    where T : TableEntity, new() 

को नोटिस कोशिशके बाद।

+0

मुझे यह त्रुटि मिल रही है- त्रुटि 'टी' सामान्य पैरामीटर या विधि – Seenu

+0

में पैरामीटर 'टेलीमेंट' के रूप में इसका उपयोग करने के लिए सार्वजनिक पैरामीटर रहित कन्स्ट्रक्टर के साथ एक गैर-सार प्रकार होना चाहिए। क्या आप कोड साझा कर सकते हैं ? –

+0

नवीनतम कोड – Seenu

संबंधित मुद्दे