searching firstname and lastname from a field containing fullname in linq c#

Viewed 4804

In my Person table, I have a field named ps_fullname that contains ..well full name of a person. In my aspx page I have a search box to filter people by name. It works fine as long as I type only ONE name. ( one word). If I type two names ( firstname lastname ) the result is zero.

here is my linq statement

string[] namelist = txtName.text.Split(' ');

DatabaseContext db = new DatabaseContext();

var query = (from person in db.People
     where
     (dhaaira == 0 ? true : (dhaaira == null ? person.ps_default_dhaaira_id == null : person.ps_default_dhaaira_id == dhaaira)) &&
     (atoll == 0 ? true : (atoll == null ? person.PAddress.Island.il_atoll_id == null : person.PAddress.Island.il_atoll_id == atoll)) &&
     (island == 0 ? true : (island == null ? person.PAddress.ad_island_id == null : person.PAddress.ad_island_id == island)) &&
     (address == 0 ? true : (address == null ? person.ps_p_add_id == null : person.ps_p_add_id == address)) &&
     (string.IsNullOrEmpty(nic) ? true : person.ps_nic.Trim().ToLower() == nic.Trim().ToLower()) &&

     (string.IsNullOrEmpty(name) ? true : ( namelist.All( n => person.ps_fullname.ToLower().Contains(n.ToLower()))))
     // orderby orderBy
     orderby person.PAddress.ad_island_id, person.ps_p_add_id, person.ps_fullname
     select person).Skip(startRowIndex).Take(maximumRows).ToList();

What am i doing wrong here? If this is too confusing can you give a simple example where I can filter a string field using multiple words.

2 Answers
Related