Linq query not behaving as expected

前端 未结 3 1908
谎友^
谎友^ 2021-01-17 16:26

I have a very simple linq query which is as following:

var result = (from r in employeeRepo.GetAll()
              where r.EmployeeName.Contains(searchString         


        
3条回答
  •  天命终不由人
    2021-01-17 16:43

    If your text has NVARCHAR datatype check for similiar letters that in reality are not the same:

    CREATE TABLE #employee (ID INT IDENTITY(1,1), EmployeeName NVARCHAR(100));
    
    INSERT INTO #employee(EmployeeName) VALUES (N'waidаnde');
    
    SELECT *
    FROM #employee
    WHERE EmployeeName LIKE '%waidande%';
    
    -- checking
    SELECT *
    FROM #employee
    WHERE CAST(EmployeeName AS VARCHAR(100)) <> EmployeeName;
    

    db<>fiddle demo

    Here: 'а' != 'a'. One is from Cyrillic 'a' and the second is normal.


    Idea taken from:

    Slide from: http://sqlbits.com/Sessions/Event12/Revenge_The_SQL

    P.S. I highly recommend to watch Rob Volk's talk: Revenge: The SQL!.

提交回复
热议问题