gpt4 book ai didi

c# - Azure 表查询问题

转载 作者:行者123 更新时间:2023-12-03 01:52:51 25 4
gpt4 key购买 nike

我正在尝试将 MS PnP CQRS 项目升级到最新的 Azure SDK,但有以下 2 个查询:

var query = new TableQuery<EventTableServiceEntity>().Where(
TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, UnpublishedRowKeyPrefix),
TableOperators.And,
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThanOrEqual, UnpublishedRowKeyPrefixUpperLimit)))
.Select(x => new { x.PartitionKey })
.AsTableQuery();

var query2 = eventTableServiceEntities
.Where(
x =>
String.Compare(x.RowKey, UnpublishedRowKeyPrefix, StringComparison.Ordinal) >= 0 &&
String.Compare(x.RowKey, UnpublishedRowKeyPrefixUpperLimit, StringComparison.Ordinal) <= 0)
.Select(x => new { x.PartitionKey }).AsTableQuery();

第一个没有错误(我认为该查询无论如何都是错误的)第二个是原始查询,现在出现错误,对象引用未设置到对象的实例

1:第二个查询有什么问题?不再支持这种风格了吗?我还没到执行它的地步!

2:第二个查询在做什么,如果 linq 样式被放弃,我将如何以查询 1 的样式表示它。

原代码如下:

https://github.com/mspnp/cqrs-journey/blob/master/source/Infrastructure/Azure/Infrastructure.Azure/EventSourcing/EventStore.cs#L215

我在这里感到困惑的事情是

x.RowKey.CompareTo(UnpublishedRowKeyPrefix) >= 0

其中UnpublishedRowKeyPrefix是:

private const string UnpublishedRowKeyPrefix = "Unpublished_";

你怎么能比较有意义呢?我错过了什么?!

eventTableServiceEntities 来自这里 - 我创建了一个变量来帮助调试:

https://github.com/dpiessens/cqrs-journey-code/blob/master/source/Infrastructure/Azure/Infrastructure.Azure/EventSourcing/EventStore.cs#L213

var eventTableServiceEntities= new TableQuery<EventTableServiceEntity>();
var query2 = eventTableServiceEntities
.Where(
x =>
String.Compare(x.RowKey, UnpublishedRowKeyPrefix, StringComparison.Ordinal) >= 0 &&
String.Compare(x.RowKey, UnpublishedRowKeyPrefixUpperLimit, StringComparison.Ordinal) <= 0)
.Select(x => new { x.PartitionKey })
.AsTableQuery();

最佳答案

您提供的字符串比较按以下方式进行:当您过滤值> =“a”和<“b”时,您将返回所有以“a”开头的字符串。因此,对于您的示例,过滤器似乎适用于以“Unpublished_”开头但低于您设置的 UnpublishedRowKeyPrefixUpperLimit 的所有字符串。至于制作 Linq 查询的帮助,此 link应该可以帮助您了解 Fluent 模式和较新的 IQueriable 模式在编写查询时的差异以及如何从一种模式转换为另一种模式。 (相关内容位于页面中间。)

关于c# - Azure 表查询问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32413378/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com