-1
db.tbluser.Where(c => c.Email == objUser.Email && c.Code.Equals(objUser.Code, StringComparison.Ordinal)).FirstOrDefault();

Specifically, when i match email and password both at same time it do not match password case sensitivity. I am using this query but it is not comparing case sensitivity of word. I want to compare LHR5P with lhr5p. It should not get value against this.

  • Does this help? https://stackoverflow.com/questions/631233/is-there-a-c-sharp-case-insensitive-equals-operator – DJ Burb Jun 09 '21 at 15:09
  • 1
    How about using `StringComparison.InvariantCultureIgnoreCase` instead of `StringComparison.Ordinal`? [This page](https://learn.microsoft.com/en-us/dotnet/api/system.stringcomparison?view=net-5.0) should help as to why the `Ordinal` wont work. – shahkalpesh Jun 09 '21 at 15:11
  • This looks like Entity Framework to me? If so, the normal C# methods won't work. – DavidG Jun 09 '21 at 15:12
  • I've closed this as a duplicate since that seems to be the problem here, though you haven't really given enough information. The dupe is quite old but has essentially the same answer. – DavidG Jun 09 '21 at 15:21
  • i have to match case sensitivity. It do not match like this db.tbluser.Where(c => c.Code == objUser.Code).FirstOrDefault(); e.g PASSworD with PaSSwoRd – Taha Ahmed Jun 11 '21 at 13:05
  • More specifically, when i match email and password both at same time it do not match password case sensitivity. i have to match case sensitivity. It do not match like this db.tbluser.Where(c => c.Email == objUser.Email && c.Code == objUser.Code).FirstOrDefault(); e.g PASSworD with PaSSwoRd – Taha Ahmed Jun 14 '21 at 06:37

1 Answers1

0

If you want it to be case sensitive just do:

db.tbluser.Where(c => c.Code == objUser.Code).FirstOrDefault();

Else if you want it insensitive just:

db.tbluser.Where(c => c.Code.ToLower() == objUser.Code.ToLower()).FirstOrDefault();