0

I want to know that,

If we have LIST object created at server side which contains large amount of data entries like employess master data(10,000), & I want to give search option to search valid employee ID or name.

So I have tried to compare that entered text with that list of large entries in loop, which is obvious degrading performance.

So is there any option to better performace?

Thanks in advance.

user1746468
  • 75
  • 2
  • 11
  • Are you trying to find out whether or not the string is already in the list? Have you tried using Linq? – Brian P Feb 13 '13 at 14:04
  • Yes your right,but I haven't used linq. I have used generic list object. Firstly I dont know much about linq. Do linq will help to enhance performance? n Thanks for reply – user1746468 Feb 13 '13 at 14:08
  • 1
    Yes, Linq will help with your performance if you are simply looping through right now... This SO Question answers it for you. http://stackoverflow.com/questions/1175645/find-an-item-in-list-by-linq – Brian P Feb 13 '13 at 14:09
  • thanks Brian P for quick replay n help.. I will try this one. – user1746468 Feb 13 '13 at 14:12

1 Answers1

0

Try this:

public List<Employee> SearchEmployee(string search, int pageNo, int pageLength)
    {
        MasterDataContext db = new MasterDataContext();
        var searchResult = (from e in db.Employess
                            where (search == null || 
                                  e.Name.ToLower().Contains(search.ToLower()))
                            select e).ToList();
        int pageStart = (pageNo - 1) * pageLength;
        var pageResult = from c in searchResult.Skip(pageStart).Take(pageLength)
                         orderby c.CardNo
                         select c;
        return pageResult;
    }

I hope it helps.

Jonas
  • 76
  • 3