是否可以从 .net 核心查询 table 存储?
Is it possible to query table storage from .net core?
我正在尝试使用 LINQ 查询 table 缓存:
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 查询 table 缓存?
关于一些附加信息,这里是 create 可用的方法 class:
这里是所有的依赖:
我已经从等式中删除了 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 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;
}
我正在尝试使用 LINQ 查询 table 缓存:
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 查询 table 缓存?
关于一些附加信息,这里是 create 可用的方法 class:
这里是所有的依赖:
我已经从等式中删除了 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 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;
}