0

I am trying to query from a table so that the name and partition key (combined) unique. I am doing this right now:

public Spec(string name)
{
    Query = new TableQuery<TableEntity>()
        .Where(TableQuery.GenerateFilterCondition(nameof(table.Name), QueryComparisons.Equal, name));
}

but I also need to check partition key exists withing this name. So need to query the table along with the partition key and the name. Can anybody help with this? How to query these as combined query.

saon
  • 591
  • 1
  • 7
  • 19
  • Table-queries are only concerned with the contents of entities' properties (columns) within a table. A table's name is completely irrelevant. – Dai Nov 25 '21 at 16:12
  • This doesn't look like real code to me - you should not have a table-type named `Table`. And what is `table.Name`? Where is it coming from? (It isn't a parameter of your method). And `public Spec(string name)` looks like a constructor - but you should not be performing IO or much heavy-lifting in a constructor (in fact, you _cannot_ do async IO in a ctor anyway). – Dai Nov 25 '21 at 16:13
  • Spec is the method I use to pass the name on it. and yes, Table is the entity class. I use Table here just for showcasing. – saon Nov 25 '21 at 16:19
  • `public Spec(string name)` is not a method, that's a constructor. It's missing its return-type. And you haven't answered my question where I ask where `table.Name` is coming from... – Dai Nov 25 '21 at 16:22

1 Answers1

1

Please try something like below:

public Spec(string name)
{
    var filterCondition1 = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "PartitionKeyValue");
    var filterCondition2 = TableQuery.GenerateFilterCondition(nameof(table.Name), QueryComparisons.Equal, name);
    Query = new TableQuery<TableEntity>()
        .Where(TableQuery.CombineFilters(filterCondition1, "AND", filterCondition2));
}
Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241