I have a silverlight app using Prism practices; the current code does a search by first name or last name or gender. regaring the names, I would like to alter the code to somethng like 3 characters because now it is searching as long as one character is found the name will display so you can see the issue, can I adjust the code here to only select those with a 3 character match? lets leave alone the issue of a name with less than 3 but we can allow anything there then.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace PBM.Web.Classes
{
public class Search
{
public static IQueryable<Patient> GetSearchQueryPatient(IQueryable<Patient> pSearchQuery, Patient pPatient)
{
if (!string.IsNullOrEmpty(pPatient.FirstName))
{
pSearchQuery = pSearchQuery.Where(item => item.FirstName.Contains(pPatient.FirstName));
}
if (!string.IsNullOrEmpty(pPatient.LastName))
{
pSearchQuery = pSearchQuery.Where(item => item.LastName.Contains(pPatient.LastName));
}
if (pPatient.Gender.HasValue && pPatient.Gender.Value > 0)
{
pSearchQuery = pSearchQuery.Where(item => item.Gender.Value == pPatient.Gender.Value);
}
pSearchQuery = pSearchQuery.OrderBy(item => item.FirstName).ThenBy(item => item.LastName);
return pSearchQuery;
}
}
}
If I’ve read your requirement and sample code correctly, simply add a length check to your tests should work:
It does mean that if the name is less than 3 characters it won’t match at all, so what you want to do is then check if this search returned anything and if not do the simple any length search: