【问题标题】:Empty table query against Azure Table Storage针对 Azure 表存储的空表查询
【发布时间】:2011-01-03 16:21:37
【问题描述】:

我正在使用 Azure 表存储。当我查询一个包含 PartitionKey 和 RowKey 以外的参数的空表时,我得到一个异常。当我至少有一行时,不会出现异常。如果我只用 PartitionKey 和 RowKey 查询空表,就可以了。

我当然不想做额外的往返来测试桌子是否是空的。人们通常如何解决这个问题?有没有一种快速检查表是否为空的高效方法?

我正在使用开发存储,因为我刚刚看到在这种情况下使用开发存储报告了错误,并且错误在生产中消失了。但是,我不想只为开发存储保留自定义代码,有没有好的方法来解决这个问题,所以我可以在本地以及生产云环境中运行相同的代码?

【问题讨论】:

  • 我分享你的痛苦 - 这是一个完整的 PITA - 它应该更容易使用!我只是禁用我的本地测试,因为我再也受不了了!
  • 回复您的编辑说明:我使用真实的存储帐户进行测试,它真的很便宜,所以我不介意它的行为 100% 符合预期。

标签: azure azure-storage azure-table-storage


【解决方案1】:

我通过将DataServiceContext.IgnoreResoureNotFoundException 属性设置为true 来解决这个问题。希望这对其他人也有帮助。

【讨论】:

    【解决方案2】:

    我无法让 IgnoreResourceNotFoundException 正常工作并将其踢出。采取了一条“顽皮”的路线,只是为了一张空桌子而陷入了异常。剪下面,享受...

    CloudTableClient _tableClient = OurStorageAccount.CreateCloudTableClient();
    CloudTable _table = _tableClient.GetTableReference( "customers" );
    
    TableQuery<CustomerEntity> _query = new TableQuery<CustomerEntity>();
    var _result = _table.ExecuteQuery( _query );
    
    StringBuilder _sb = new StringBuilder(1024);
    try
    { 
    	_sb.AppendLine("Begin listing customers....<br/>");
    	foreach ( CustomerEntity _customer in _result )
    	{
    		_sb.AppendFormat( "{0} {1} - {2} - {3}<br/>", _customer.PartitionKey, _customer.RowKey, _customer.Email, _customer.PhoneNumber );
    	}
    	_sb.AppendLine("End listing customers....<br/>");
    }
    catch ( System.NullReferenceException _nullEx )
    { 
    	_sb.Append( System.DateTime.Now.ToString() );
    	_sb.AppendLine( ": no customer entries found<br/>" );
    	System.Diagnostics.Debug.WriteLine( _nullEx.ToString());
    	// _sb.AppendLine( _nullEx.ToString() );
    }
    catch (Exception _ex)
    {
    	_sb.AppendLine("unkown exception thrown, good luck<br/>");
    	_sb.AppendLine( _ex.ToString() );
    }
    
    Label_Output.Text = _sb.ToString();

    【讨论】:

      猜你喜欢
      • 2018-12-07
      • 2011-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-11
      • 1970-01-01
      • 2021-09-07
      相关资源
      最近更新 更多