Search from the string array and ignore that exact matched string

Miranda

how can I ignore the exact matched from the string array with linq query

here is my code whats wrong with it

public string GetItems(string SearchText, Int64 userID, Int64 orgID, Int64 locationID, string[] selectedProductName)
{
    List<Product> searchList = new List<Product>();
    string jsonText = "";
    try
    {            
            searchList = dbContext.usp_ang_GetProductList_(orgID, SearchText, locationID, 0).ToList();
            var abc = searchList.Where(a => a.Name.Any(a.Name != selectedProductName).ToList();
            jsonText = JsonConvert.SerializeObject(abc);            
    }
    catch (Exception ex)
    {

    }
    return jsonText;
}
Gilad Green

Your use of the .Any is incorrect:

  1. In your current use you are checking if any of the chars that construct a.name match some predicate.
  2. .Any(a.Name != selectedProductName) - you need to form a properly formatted lambda expression

You want to check if any of the values of the selectedProductName array is equals to the a.Name.

var abc = searchList.Where(a => !selectedProductName.Any(name => name == a.Name)).ToList();

Because selectedProductName is a string[] it is cleaner just to use .Contains:

var abc = searchList.Where(a => !selectedProductName.Contains(a.Name)).ToList();

Also it is a shame to bring all that data from the database just to filter it the row after. If you remove the ToList() the filtering will happen in the database:

var abc = dbContext.usp_ang_GetProductList_(orgID, SearchText, locationID, 0)
                   .Where(a => !selectedProductName.Contains(a.Name)).ToList();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

search exact string in string array?

From Dev

Remove string characters from a string if not matched in an array

From Dev

Remove string characters from a string if not matched in an array

From Dev

Elastic search: exact match query on string array

From Dev

Search for exact string in column

From Dev

Search string from end of matched word up to X

From Dev

search an string array using given user and return indexes of the matched string array

From Dev

TSQL search exact match into a string

From Dev

Exact string search in XML files?

From Dev

Search String array for String

From Dev

Search string from array and reference array number

From Dev

Specific(exact) characters from char array to string C#

From Dev

PHP get array of search terms from string

From Dev

search in string from an array of keys. PHP

From Dev

Javascript search replace string from array

From Dev

regex to exact values from a string

From Dev

Excel - Search an exact match within a string

From Dev

Excel - Search an exact match within a string

From Dev

Using grep in shell script to search for exact string

From Dev

How to search for the exact string value in MySQL?

From Dev

PYTHON: search for exact string in text document

From Dev

Log all instances of a matched string in a array - JavaScript

From Dev

Perl code to find an array element in a sentence and then to look either side of the match for another string to be matched from a different array

From Dev

Java - search a string in string array

From Dev

Java - search a string in string array

From Dev

Create two dimensional array from string, but ignore a specific character

From Dev

Ignore trailing NULL characters when converting string from char array

From Dev

Create two dimensional array from string, but ignore a specific character

From Dev

How do I search for exact word in a String array which contain sentences(JAVA)

Related Related

  1. 1

    search exact string in string array?

  2. 2

    Remove string characters from a string if not matched in an array

  3. 3

    Remove string characters from a string if not matched in an array

  4. 4

    Elastic search: exact match query on string array

  5. 5

    Search for exact string in column

  6. 6

    Search string from end of matched word up to X

  7. 7

    search an string array using given user and return indexes of the matched string array

  8. 8

    TSQL search exact match into a string

  9. 9

    Exact string search in XML files?

  10. 10

    Search String array for String

  11. 11

    Search string from array and reference array number

  12. 12

    Specific(exact) characters from char array to string C#

  13. 13

    PHP get array of search terms from string

  14. 14

    search in string from an array of keys. PHP

  15. 15

    Javascript search replace string from array

  16. 16

    regex to exact values from a string

  17. 17

    Excel - Search an exact match within a string

  18. 18

    Excel - Search an exact match within a string

  19. 19

    Using grep in shell script to search for exact string

  20. 20

    How to search for the exact string value in MySQL?

  21. 21

    PYTHON: search for exact string in text document

  22. 22

    Log all instances of a matched string in a array - JavaScript

  23. 23

    Perl code to find an array element in a sentence and then to look either side of the match for another string to be matched from a different array

  24. 24

    Java - search a string in string array

  25. 25

    Java - search a string in string array

  26. 26

    Create two dimensional array from string, but ignore a specific character

  27. 27

    Ignore trailing NULL characters when converting string from char array

  28. 28

    Create two dimensional array from string, but ignore a specific character

  29. 29

    How do I search for exact word in a String array which contain sentences(JAVA)

HotTag

Archive