简体   繁体   English

在Azure Table Storage SDK中,GenerateFilterCondition的用途是什么?

[英]In the Azure Table Storage SDK, what is the purpose of GenerateFilterCondition?

In the Azure Table Storage SDK documentation , there are numerous examples of constructing LINQ queries over Tables using code in the form: Azure Table Storage SDK文档中 ,有许多示例使用以下形式的代码在Tables上构造LINQ查询:

TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Smith"));

I understand that GenerateFilterCondition creates a predicate to pass to Where - which works in the same way a (for example) Func<CustomerEntity, bool> would, but I can't find anything that explains why it's required as opposed to writing: 我知道GenerateFilterCondition会创建一个传递给Where的谓词-它以(例如) Func<CustomerEntity, bool>的相同方式工作,但是我找不到能解释为什么需要它而不是编写的内容:

TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>().Where(c => c.PartitionKey == "Smith");

What does this helper method do for you that writing a straightforward lambda expression like 'normal' LINQ does not? 这种辅助方法对您有什么作用,而编写像“普通” LINQ这样的简单的lambda表达式却对您没有帮助?

May be it caused by strong assumption, that you will almost always query data by specifing RowKey and PartitionKey - it is fast(due to inner azure storage tables architecture) and predictable, but if you want to build more complex search condition, you should use TableQuery.GenerateFilterCondition builder instead of standart Entity Framework .Where like predicate, ie Expression<Func<T, bool>> . 可能是由于强烈的假设所致,您几乎总是通过指定RowKeyPartitionKey来查询数据-这是快速的(由于内部天蓝色存储表架构)并且可预测,但是如果要构建更复杂的搜索条件,则应使用TableQuery.GenerateFilterCondition构建器代替标准的Entity Framework .Where类似于谓词,即Expression<Func<T, bool>> Also I think TableQuery.GenerateFilterCondition will not offer you something special except of goal opportunities. 我还认为TableQuery.GenerateFilterCondition除了目标机会之外,不会为您提供一些特别的东西。

If you want to use comfortable predicate syntax, you can use Azure.TableStorage.API library, which allow you to write queries like this: 如果要使用舒适的谓词语法,则可以使用Azure.TableStorage.API库,该库允许您编写如下查询:

var api = new AzureTableStorageAPI();
var date = new DateTime(1990, 1, 10);
var persons = api.GetEntities<Person>(x => x.BirthDay > date && x.PartitionKey == "Man" && (x.Age > 30 || x.Name == "Mike"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM