I'm attempting to query table cache using 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);
}
However, getting this exception:
'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?)
What am I doing wrong? Is it not possible to query table cache from .net core?
For some additinal info, here are the create methods available on this class:
Here are all the dependencies:
I've removed LINQ from the equation, yet still getting the following issue:
And the full source is below:
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();
}
Currently .net core doesn't support querying using Linq as far as I know. But I know You can do it this
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();
EDIT: GitHub issue
EDIT 2: ExecuteQuery extension method
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With