none
LINQ to Entities with string comparison? RRS feed

  • Question

  • I have some SQL that I cannot figure out how to translate to LINQ. Specifically the SQL compares values against a string filter using the string comparison functions in MySQL, but there does not appear to be any way to compare string values with anything except equality operators in LINQ? For instance, if we have the following SQL:

    select name
    from products p
    where name >= 'startFilter' and 
         name <= 'endFilter'
    

    there appears to be now way to convert this to LINQ? Obviously in the above SQL, the products.name column is a string value. Is there any way to do this?

     

    Wednesday, July 6, 2011 1:37 AM

Answers

  • Hi,

    You could try to use the string class CompareTo method, this will be converted to <= and >=

    eg.

    .Where(row => row.Name.CompareTo("Comparestring") > 0)

    will be converted to

    Where Name > 'Comparestring'


    --Rune
    Wednesday, July 6, 2011 1:42 PM

All replies