Melih
Melih

Reputation: 568

MVC EntityFramework, search from Database table?

I want to search in my mvc project. But All time I can't get rows.. I take devicename in textbox.

my code:

List<Tablename> list = db.Tablename
                         .Where(c => c.Devices.devName.ToLower().Contains(devicename.ToLower()))
                         .OrderBy(c => c.dateTime)
                         .Skip(skip)
                         .Take(pageSize).ToList();

I can't see any rows in table. But when I wrote this, it's work but it can't do same thing "LİKE" .

 List<Tablename> list = db.Tablename
                          .Where(c => c.Devices.devNameEquals(devicename)))
                          .OrderBy(c => c.dateTime)
                          .Skip(skip)
                          .Take(pageSize).ToList();

Upvotes: 1

Views: 1101

Answers (1)

Chris L
Chris L

Reputation: 2292

Is there any whitespace before or after the string from the text box?

List<Tablename> list = db.Tablename
                         .Where(c => c.Devices.devName.ToLower()
                         .Contains((devicename.Trim()).ToLower()))
                         .OrderBy(c => c.dateTime)
                         .Skip(skip)
                         .Take(pageSize).ToList();

Upvotes: 1

Related Questions