I'm trying to do a text search on a partial property match on related entities.
My entities are:
public class TradeContact
{
[Key]
public int TradeContactId { get; set; }
public virtual ICollection<Region> Regions { get; set; }
}
public class Region
{
[Key]
public int RegionId { get; set; }
public virtual ICollection<TradeContact> TradeContacts { get; set; }
}
My goal is that if a TradeContact has the following regions: Sydney, Brisbane, Darwin, then I should be able to search for 'Syd' to retrieve that TradeContact record.
Currently I'm searching like this:
TradeContacts = TradeContacts
.Where(s => s.Regions.Select(x => x.Name.ToUpper())
.Contains(searchString.ToUpper()));
This code finds full matches, so 'Sydney' will return my TradeContact, but it doesn't work on partial matches.
What have I done wrong?