gpt4 book ai didi

c# - 是否可以从 .net core 查询表存储?

转载 作者:行者123 更新时间:2023-11-30 14:21:35 25 4
gpt4 key购买 nike

我正在尝试使用 LINQ 查询表缓存:

public static IEnumerable<DocumentMetaDataEntity> Get(string connectionString, string cacheName, DeconstructedFileName deconstructedFileName, FileMetaDataFilters filters)
{
var acc = CloudStorageAccount.Parse(connectionString);
var tableClient = acc.CreateCloudTableClient();
var table = tableClient.GetTableReference(cacheName);
var translations = from entity in table.CreateQuery<DocumentMetaDataEntity>()
where (entity.sourceParty == sourceParty.ToLowerTrim()
&& entity.destinationParty == destinationParty.ToLowerTrim())
|| (entity.sourceParty == "YES"
&& entity.destinationParty == destinationParty.ToLowerTrim())
select entity;

return translations.Where(x => x.expireAt > DateTime.Now)
.Where(x => x.effectiveAt < DateTime.Now);
}

但是,得到这个异常:

'CloudTable' does not contain a definition for 'CreateQuery' and no accessible extension method 'CreateQuery' accepting a first argument of type 'CloudTable' could be found (are you missing a using directive or an assembly reference?)

我做错了什么? .net core 无法查询表缓存吗?

enter image description here

对于一些附加信息,这里是此类上可用的创建方法:

enter image description here

这里是所有的依赖:

enter image description here

我已经从等式中删除了 LINQ,但仍然遇到以下问题:

enter image description here

完整的源代码如下:

public static IEnumerable<DocumentMetaDataEntity> Get(string connectionString, string cacheName, DeconstructedFileName deconstructedFileName, FileMetaDataFilters filters)
{
var acc = CloudStorageAccount.Parse(connectionString);
var tableClient = acc.CreateCloudTableClient();
var table = tableClient.GetTableReference(cacheName);
var query = new TableQuery<DocumentMetaDataEntity>().Where
(TableQuery.CombineFilters
(TableQuery.GenerateFilterCondition("FacilityCode", QueryComparisons.Equal, deconstructedFileName.FacilityCode)
, TableOperators.And
, TableQuery.GenerateFilterCondition("LastName", QueryComparisons.LessThan, deconstructedFileName.LastName)
)
);

var entities = table.ExecuteQuery(query).ToList();
}

最佳答案

据我所知,目前 .net core 不支持使用 Linq 进行查询。但我知道你可以做到这一点

var table = acc.GetTableReference("TableName");

var partitionKey = "PartitionKey";

TableQuery<TableModel> rangeQuery = new TableQuery<TableModel>()
.Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey.ToString()));

var entities = table.ExecuteQuery(rangeQuery).ToList();

编辑:GitHub issue

编辑 2:ExecuteQuery 扩展方法

public static IEnumerable<T> ExecuteQuery<T>(this CloudTable table, TableQuery<T> query) where T : ITableEntity, new()
{
List<T> result = new List<T>();

TableContinuationToken continuationToken = null;
do
{
// Retrieve a segment (up to 1,000 entities).
TableQuerySegment<T> tableQueryResult = table.ExecuteQuerySegmentedAsync(query, continuationToken).Result;

result.AddRange(tableQueryResult.Results);

continuationToken = tableQueryResult.ContinuationToken;
} while (continuationToken != null);

return result;
}

关于c# - 是否可以从 .net core 查询表存储?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54351868/

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