In the database in the Customer table there is a FirstName field. Its content may be absolutely random register, for example, "IvANov". Naturally, if I check for "Ivanov" the result will be empty. Make c.FirstName.Upper () naturally does not.

var customers = t.Customers .Where(c => c.FirstName.Contains(findToolStripTextBox.Text); 

The current code version (t = new mydb: DbContext). How to do it right?

StringComparer.InvariantCultureIgnoreCase - this also does not work.

  • And if in the database, the corresponding field is put in order and subsequently entered in the same way: we bring the Last Name to the form and we do the same thing entered by the user on the client before the search - Bald
  • Specify which DBMS you use. Describe how the database was created (code first, database first, etc), with what settings. EF defaults to case in most cases. - Alexander Petrov
  • postgres 9.3 code-first - Krona battery
  • It’s problematic to bring a single mind, and it’s not right either ... There are double names, with spaces, and so on. - Krona battery
  • Do not forget to specify the nickname of the user with the preceding @ symbol of the form @ Nickname of the user (necessary for receiving notification). as an option, you can try to form a raw sql query of something like: context.Customers.SqlQuery("Select * from Customers where FirstName like '%@firstName%'", new SqlParameter() {}); - Bald

1 answer 1

Match to one register and compare:

 var customers = t.Customers .Where(c => c.FirstName.ToLower().Contains(findToolStripTextBox.Text.ToLower());