Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linq query for varchar field not returning any results

When I run this query in linqpad:

Customer.Where(c => (c.CustomerName == "test"))

It returns a record that matches.

When I try running the same query in visual studio it does not return any matching records. This is the code I am using:

    List<Customer> customerList = new List<Customer>();

    using (DBEntities db = new DBEntities())
    {
        try
        {
            customerList = db.Customer.Where(c => (c.customerName == "test")).ToList();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }

    return customerList;

Can anyone see why this it works in linqpad but does not work in visual studio?

like image 290
user1696698 Avatar asked Dec 19 '12 10:12

user1696698


1 Answers

can you try out like this

customerList = db.Customer.
   Where(c => String.Compare (c.customerName.ToUpper(),"test".ToUpper()) == 0).ToList();

because there may be problem with the Casesensitive search for customer name.

Try other variation of : String.Compare Method as per you need

like image 111
Pranay Rana Avatar answered Oct 05 '22 13:10

Pranay Rana