Linq query: Filter out "-" character in field from source via Select statement RRS feed

  • Question

  • My "socialsecuritynumber" contains a "-" character, fx. 123456-8888, that I want to remove before searching for a match.

    However, I seem to be doing something wrong. In the “Foreach” it is no problem, but I want to place it in my Select statement.

    Hope you can help :-)

                var contactquery = (
                    from c in xrm.ContactSet
                    join bu in xrm.BusinessUnitSet on c.OwningBusinessUnit.Id equals bu.BusinessUnitId
                    where bu.Name == businessunit
                    //where c.socialsecuritynumber.Contains(input)            [WORKS]
                    //where Char.IsDigit(c.socialsecuritynumber).Contains(input)             [DOES NOT WORK]
                    select new { c.ContactId, c.socialsecuritynumber, c.FullName }

    Tuesday, February 25, 2014 7:11 AM


  • You can not do this in the CRM LINQ query itself. The query is translated to a QueryExpression and therefore the LINQ syntax is limited by the capabilities of the QueryExpression.

    Maybe you can insert the hyphen in the input argument before querying the ContactSet?

    If this post is an answer or helpful, please do not forget to vote!

    Tuesday, February 25, 2014 9:05 PM