Azure Table 存储 - 查询 return 其他数据所在的位置
Azure Table Storage - Query Where return other data
我不确定为什么,但我正在使用谓词 City
= London
查询数据库,但我收到的实体具有不同的值
这是我的数据模型:
public class MyEntity : TableEntity
{
public MyEntity()
{
}
public MyEntity(string partitionKey, string rowKey) : base(partitionKey, rowKey)
{
}
public string City { get; set; }
public string Year { get; set; }
}
我的查询:
var query = new TableQuery<KomisEntity>()
.Where(TableQuery.GenerateFilterCondition("City", QueryComparisons.Equal, "London"))
.Where(TableQuery.GenerateFilterCondition("Year", QueryComparisons.Equal, "2000"));
var data = await LoadWhereAsync(table, query);
辅助方法:
private static async Task<List<T>> LoadWhereAsync<T>(CloudTable table, TableQuery<T> query) where T : TableEntity, new()
{
var entities = new List<T>();
TableContinuationToken continuationToken = null;
do
{
var page = await table.ExecuteQuerySegmentedAsync(query, continuationToken);
continuationToken = page.ContinuationToken;
entities.AddRange(page);
}
while (continuationToken != null);
return entities;
}
但出于某种原因,我正在接收实体,例如:
City: 'South Pierceberg'
提前致谢
问题是由于您的查询过滤器:
var query = new TableQuery<KomisEntity>()
.Where(TableQuery.GenerateFilterCondition("City", QueryComparisons.Equal, "London"))
.Where(TableQuery.GenerateFilterCondition("Year", QueryComparisons.Equal, "2000"));
这应该会生成一个像这样的 or
过滤器 city==London or Year==2000
。
您可以试试下面的代码,它使用了 and
过滤器:
string filter = "(City eq 'London') and (Year eq '2000')";
var query = new TableQuery<KomisEntity>().Where(filter);
或使用此查询格式:
var query = new TableQuery<KomisEntity>().Where(
TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("City", QueryComparisons.Equal, "London"),
TableOperators.And,
TableQuery.GenerateFilterCondition("Year", QueryComparisons.Equal, "2000")
)
);
我不确定为什么,但我正在使用谓词 City
= London
查询数据库,但我收到的实体具有不同的值
这是我的数据模型:
public class MyEntity : TableEntity
{
public MyEntity()
{
}
public MyEntity(string partitionKey, string rowKey) : base(partitionKey, rowKey)
{
}
public string City { get; set; }
public string Year { get; set; }
}
我的查询:
var query = new TableQuery<KomisEntity>()
.Where(TableQuery.GenerateFilterCondition("City", QueryComparisons.Equal, "London"))
.Where(TableQuery.GenerateFilterCondition("Year", QueryComparisons.Equal, "2000"));
var data = await LoadWhereAsync(table, query);
辅助方法:
private static async Task<List<T>> LoadWhereAsync<T>(CloudTable table, TableQuery<T> query) where T : TableEntity, new()
{
var entities = new List<T>();
TableContinuationToken continuationToken = null;
do
{
var page = await table.ExecuteQuerySegmentedAsync(query, continuationToken);
continuationToken = page.ContinuationToken;
entities.AddRange(page);
}
while (continuationToken != null);
return entities;
}
但出于某种原因,我正在接收实体,例如:
City: 'South Pierceberg'
提前致谢
问题是由于您的查询过滤器:
var query = new TableQuery<KomisEntity>()
.Where(TableQuery.GenerateFilterCondition("City", QueryComparisons.Equal, "London"))
.Where(TableQuery.GenerateFilterCondition("Year", QueryComparisons.Equal, "2000"));
这应该会生成一个像这样的 or
过滤器 city==London or Year==2000
。
您可以试试下面的代码,它使用了 and
过滤器:
string filter = "(City eq 'London') and (Year eq '2000')";
var query = new TableQuery<KomisEntity>().Where(filter);
或使用此查询格式:
var query = new TableQuery<KomisEntity>().Where(
TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("City", QueryComparisons.Equal, "London"),
TableOperators.And,
TableQuery.GenerateFilterCondition("Year", QueryComparisons.Equal, "2000")
)
);