AND operation using TableQuery.CombineFilters on a List










0















How can I assign initial value to myQuery where I am appending conditions using AND and a foreach loop.



I am trying to do the following:



string myQuery = string.empty;

foreach (string myCondition in myConditionLists)

myQuery = TableQuery.CombineFilters(
myQuery,
TableOperators.And,
TableQuery.GenerateFilterCondition(nameof(MyClass.MyProperty),
QueryComparisons.NotEqual, myCondition));



When I debug, I see an initial statement of "()" which doesn't seem right. Another approach would be to assign query the first element into myQuery and grow from the second element. Is there an elegant way to do this?










share|improve this question
























  • Hello, does the answer below work for you?

    – Ivan Yang
    Nov 16 '18 at 8:03











  • Initial test shows that it works, but I will do some more testing to confirm.

    – Shamim Hafiz
    Nov 16 '18 at 8:32






  • 1





    Any updates? :)

    – Ivan Yang
    Nov 22 '18 at 11:48















0















How can I assign initial value to myQuery where I am appending conditions using AND and a foreach loop.



I am trying to do the following:



string myQuery = string.empty;

foreach (string myCondition in myConditionLists)

myQuery = TableQuery.CombineFilters(
myQuery,
TableOperators.And,
TableQuery.GenerateFilterCondition(nameof(MyClass.MyProperty),
QueryComparisons.NotEqual, myCondition));



When I debug, I see an initial statement of "()" which doesn't seem right. Another approach would be to assign query the first element into myQuery and grow from the second element. Is there an elegant way to do this?










share|improve this question
























  • Hello, does the answer below work for you?

    – Ivan Yang
    Nov 16 '18 at 8:03











  • Initial test shows that it works, but I will do some more testing to confirm.

    – Shamim Hafiz
    Nov 16 '18 at 8:32






  • 1





    Any updates? :)

    – Ivan Yang
    Nov 22 '18 at 11:48













0












0








0








How can I assign initial value to myQuery where I am appending conditions using AND and a foreach loop.



I am trying to do the following:



string myQuery = string.empty;

foreach (string myCondition in myConditionLists)

myQuery = TableQuery.CombineFilters(
myQuery,
TableOperators.And,
TableQuery.GenerateFilterCondition(nameof(MyClass.MyProperty),
QueryComparisons.NotEqual, myCondition));



When I debug, I see an initial statement of "()" which doesn't seem right. Another approach would be to assign query the first element into myQuery and grow from the second element. Is there an elegant way to do this?










share|improve this question
















How can I assign initial value to myQuery where I am appending conditions using AND and a foreach loop.



I am trying to do the following:



string myQuery = string.empty;

foreach (string myCondition in myConditionLists)

myQuery = TableQuery.CombineFilters(
myQuery,
TableOperators.And,
TableQuery.GenerateFilterCondition(nameof(MyClass.MyProperty),
QueryComparisons.NotEqual, myCondition));



When I debug, I see an initial statement of "()" which doesn't seem right. Another approach would be to assign query the first element into myQuery and grow from the second element. Is there an elegant way to do this?







c# azure-table-storage azure-tablequery






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 20:57









Rufus L

17.8k31531




17.8k31531










asked Nov 12 '18 at 19:03









Shamim HafizShamim Hafiz

12.1k3088152




12.1k3088152












  • Hello, does the answer below work for you?

    – Ivan Yang
    Nov 16 '18 at 8:03











  • Initial test shows that it works, but I will do some more testing to confirm.

    – Shamim Hafiz
    Nov 16 '18 at 8:32






  • 1





    Any updates? :)

    – Ivan Yang
    Nov 22 '18 at 11:48

















  • Hello, does the answer below work for you?

    – Ivan Yang
    Nov 16 '18 at 8:03











  • Initial test shows that it works, but I will do some more testing to confirm.

    – Shamim Hafiz
    Nov 16 '18 at 8:32






  • 1





    Any updates? :)

    – Ivan Yang
    Nov 22 '18 at 11:48
















Hello, does the answer below work for you?

– Ivan Yang
Nov 16 '18 at 8:03





Hello, does the answer below work for you?

– Ivan Yang
Nov 16 '18 at 8:03













Initial test shows that it works, but I will do some more testing to confirm.

– Shamim Hafiz
Nov 16 '18 at 8:32





Initial test shows that it works, but I will do some more testing to confirm.

– Shamim Hafiz
Nov 16 '18 at 8:32




1




1





Any updates? :)

– Ivan Yang
Nov 22 '18 at 11:48





Any updates? :)

– Ivan Yang
Nov 22 '18 at 11:48












1 Answer
1






active

oldest

votes


















1














You can specify an integer value and in your loop it adds 1 for each iteration. When it equals 1, you set the initial value to myQuery string.



The sample code is below:



 static void Main(string args)

CloudStorageAccount storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("your_account", "your_key"),true);

// Create the table client.
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

// Create the CloudTable object that represents the "people" table.
CloudTable table = tableClient.GetTableReference("people");

string myQuery = string.Empty;

List<string> myConditionLists = new List<string>();
myConditionLists.Add("Ben1");
myConditionLists.Add("Ben2");
myConditionLists.Add("Ben3");
myConditionLists.Add("Ben4");
myConditionLists.Add("Ben5");

//specify an integer value
int i = 0;

foreach (string myCondition in myConditionLists)

i++;
//if i == 1, specify the initial value to the myQuery string.
if (i == 1) myQuery = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.NotEqual, myCondition);
else

myQuery = TableQuery.CombineFilters(
myQuery,
TableOperators.And,
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.NotEqual, myCondition)
);



TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>().Where(myQuery);

foreach (CustomerEntity entity in table.ExecuteQuery(query))

Console.WriteLine("0, 1t2t3", entity.PartitionKey, entity.RowKey,
entity.Email, entity.PhoneNumber);



Console.WriteLine("---completed---");
Console.ReadLine();



My table:



enter image description here



The test result:



enter image description here






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268520%2fand-operation-using-tablequery-combinefilters-on-a-list%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You can specify an integer value and in your loop it adds 1 for each iteration. When it equals 1, you set the initial value to myQuery string.



    The sample code is below:



     static void Main(string args)

    CloudStorageAccount storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("your_account", "your_key"),true);

    // Create the table client.
    CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

    // Create the CloudTable object that represents the "people" table.
    CloudTable table = tableClient.GetTableReference("people");

    string myQuery = string.Empty;

    List<string> myConditionLists = new List<string>();
    myConditionLists.Add("Ben1");
    myConditionLists.Add("Ben2");
    myConditionLists.Add("Ben3");
    myConditionLists.Add("Ben4");
    myConditionLists.Add("Ben5");

    //specify an integer value
    int i = 0;

    foreach (string myCondition in myConditionLists)

    i++;
    //if i == 1, specify the initial value to the myQuery string.
    if (i == 1) myQuery = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.NotEqual, myCondition);
    else

    myQuery = TableQuery.CombineFilters(
    myQuery,
    TableOperators.And,
    TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.NotEqual, myCondition)
    );



    TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>().Where(myQuery);

    foreach (CustomerEntity entity in table.ExecuteQuery(query))

    Console.WriteLine("0, 1t2t3", entity.PartitionKey, entity.RowKey,
    entity.Email, entity.PhoneNumber);



    Console.WriteLine("---completed---");
    Console.ReadLine();



    My table:



    enter image description here



    The test result:



    enter image description here






    share|improve this answer





























      1














      You can specify an integer value and in your loop it adds 1 for each iteration. When it equals 1, you set the initial value to myQuery string.



      The sample code is below:



       static void Main(string args)

      CloudStorageAccount storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("your_account", "your_key"),true);

      // Create the table client.
      CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

      // Create the CloudTable object that represents the "people" table.
      CloudTable table = tableClient.GetTableReference("people");

      string myQuery = string.Empty;

      List<string> myConditionLists = new List<string>();
      myConditionLists.Add("Ben1");
      myConditionLists.Add("Ben2");
      myConditionLists.Add("Ben3");
      myConditionLists.Add("Ben4");
      myConditionLists.Add("Ben5");

      //specify an integer value
      int i = 0;

      foreach (string myCondition in myConditionLists)

      i++;
      //if i == 1, specify the initial value to the myQuery string.
      if (i == 1) myQuery = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.NotEqual, myCondition);
      else

      myQuery = TableQuery.CombineFilters(
      myQuery,
      TableOperators.And,
      TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.NotEqual, myCondition)
      );



      TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>().Where(myQuery);

      foreach (CustomerEntity entity in table.ExecuteQuery(query))

      Console.WriteLine("0, 1t2t3", entity.PartitionKey, entity.RowKey,
      entity.Email, entity.PhoneNumber);



      Console.WriteLine("---completed---");
      Console.ReadLine();



      My table:



      enter image description here



      The test result:



      enter image description here






      share|improve this answer



























        1












        1








        1







        You can specify an integer value and in your loop it adds 1 for each iteration. When it equals 1, you set the initial value to myQuery string.



        The sample code is below:



         static void Main(string args)

        CloudStorageAccount storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("your_account", "your_key"),true);

        // Create the table client.
        CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

        // Create the CloudTable object that represents the "people" table.
        CloudTable table = tableClient.GetTableReference("people");

        string myQuery = string.Empty;

        List<string> myConditionLists = new List<string>();
        myConditionLists.Add("Ben1");
        myConditionLists.Add("Ben2");
        myConditionLists.Add("Ben3");
        myConditionLists.Add("Ben4");
        myConditionLists.Add("Ben5");

        //specify an integer value
        int i = 0;

        foreach (string myCondition in myConditionLists)

        i++;
        //if i == 1, specify the initial value to the myQuery string.
        if (i == 1) myQuery = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.NotEqual, myCondition);
        else

        myQuery = TableQuery.CombineFilters(
        myQuery,
        TableOperators.And,
        TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.NotEqual, myCondition)
        );



        TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>().Where(myQuery);

        foreach (CustomerEntity entity in table.ExecuteQuery(query))

        Console.WriteLine("0, 1t2t3", entity.PartitionKey, entity.RowKey,
        entity.Email, entity.PhoneNumber);



        Console.WriteLine("---completed---");
        Console.ReadLine();



        My table:



        enter image description here



        The test result:



        enter image description here






        share|improve this answer















        You can specify an integer value and in your loop it adds 1 for each iteration. When it equals 1, you set the initial value to myQuery string.



        The sample code is below:



         static void Main(string args)

        CloudStorageAccount storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("your_account", "your_key"),true);

        // Create the table client.
        CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

        // Create the CloudTable object that represents the "people" table.
        CloudTable table = tableClient.GetTableReference("people");

        string myQuery = string.Empty;

        List<string> myConditionLists = new List<string>();
        myConditionLists.Add("Ben1");
        myConditionLists.Add("Ben2");
        myConditionLists.Add("Ben3");
        myConditionLists.Add("Ben4");
        myConditionLists.Add("Ben5");

        //specify an integer value
        int i = 0;

        foreach (string myCondition in myConditionLists)

        i++;
        //if i == 1, specify the initial value to the myQuery string.
        if (i == 1) myQuery = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.NotEqual, myCondition);
        else

        myQuery = TableQuery.CombineFilters(
        myQuery,
        TableOperators.And,
        TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.NotEqual, myCondition)
        );



        TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>().Where(myQuery);

        foreach (CustomerEntity entity in table.ExecuteQuery(query))

        Console.WriteLine("0, 1t2t3", entity.PartitionKey, entity.RowKey,
        entity.Email, entity.PhoneNumber);



        Console.WriteLine("---completed---");
        Console.ReadLine();



        My table:



        enter image description here



        The test result:



        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 13 '18 at 2:52

























        answered Nov 13 '18 at 2:40









        Ivan YangIvan Yang

        2,799126




        2,799126



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268520%2fand-operation-using-tablequery-combinefilters-on-a-list%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo