locked
How to do a case-sensitive search using EF RRS feed

  • Question

  • I'm using ADO.NET EF 3.5. I need to do a case-sensitive search (on a password field):

     

    using (UserEntities context = new UserEntities(strCon))

    {

     

     

    PortalUser pu;

    pu = (

    from u in context.PortalUser

    where

     

    u.UserName == userName && u.InitialPassword == pwd

     

    //where u.UserName == userName && u.InitialPassword.Equals(pwd, StringComparison.CurrentCulture)

     

    select u).FirstOrDefault();

    }


    I tryied both "==" and "Equals", but the search is always case-insensitive. Can anyone help me?

    Thanks,

    Sheng

    Thursday, February 11, 2010 3:50 PM

Answers

  • You can change the collation property of the column in SQL Server.
    ALTER TABLE PortalUser
        ALTER COLUMN InitialPassword VARCHAR(20) 
        COLLATE Latin1_General_CS_AS 
    GO 


    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    • Marked as answer by Pierreshiny Thursday, February 11, 2010 10:27 PM
    Thursday, February 11, 2010 4:27 PM

All replies

  • You can change the collation property of the column in SQL Server.
    ALTER TABLE PortalUser
        ALTER COLUMN InitialPassword VARCHAR(20) 
        COLLATE Latin1_General_CS_AS 
    GO 


    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    • Marked as answer by Pierreshiny Thursday, February 11, 2010 10:27 PM
    Thursday, February 11, 2010 4:27 PM
  • Thanks Sheng!

    We have the same name!

    Sheng

    Thursday, February 11, 2010 10:27 PM