How to use wildcards with LINQ?

How do I modify a LINQ query so that orgainizationName includes wildcards? If organizationName is "ABC," I need "ABC (Miami, FL)." The template is always orgName followed by a space, and then in parentheses "()" is 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();

Thank!

+3
source share
3 answers
on.OrganizationName.StartsWith(organizationName + " (");
0
source
var orgId = dc.Contacts.Where(on =>
    on.ContactTypeID == 2 &&
    on.IsActive == true &&
    on.OrganizationName.StartsWith(organizationName))
        .Select(on => on.ContactID).SingleOrDefault();
+1
source

you can use on.OrganizationName.StartsWith(organizationName)

0
source

Source: https://habr.com/ru/post/1793941/


All Articles