DenaliHardtail
DenaliHardtail

Reputation: 28336

How do I use wildcards with LINQ?

How do I modify the follwing LINQ query so that orgainizationName includes wildcards? If organizationName is 'ABC', I need 'ABC (Miami, FL)' returned. The pattern is always orgName followed by a space and then, in parentheses "()", the city and state.

var orgId = dc.Contacts.Where(on =>
on.ContactTypeID == 2 &&
on.IsActive == true &&
on.OrganizationName.Contains(organizationName)
)
.Select(on => on.ContactID).SingleOrDefault();

Thanks!

Upvotes: 3

Views: 220

Answers (3)

Bradley Swain
Bradley Swain

Reputation: 814

You could use on.OrganizationName.StartsWith(organizationName)

Upvotes: 0

xanatos
xanatos

Reputation: 111940

on.OrganizationName.StartsWith(organizationName + " (");

Upvotes: 0

Mike Atlas
Mike Atlas

Reputation: 8241

var orgId = dc.Contacts.Where(on =>
    on.ContactTypeID == 2 &&
    on.IsActive == true &&
    on.OrganizationName.StartsWith(organizationName))
        .Select(on => on.ContactID).SingleOrDefault();

Upvotes: 1

Related Questions