c# - WildCard Search Using Linq -
i having cardtable values
cardtable
id card no ------- ---------- 1 | 0001-1234-5678-9001 2 | 0001-1234-5678-9002 3 | 0001-1234-5678-9003 4 | 0001-1234-5678-9004 5 | 0001-1234-5678-9005
now want search in table using linq
card no
i.e. 0001-1234-5678-9001
(using number directly) or 0001123456789001
(using number without dashes)
can in this?
in comments other answers have indicated want execute query on server side. can converting card number canonical card number has format used in database:
string getcanonicalcardno(string cardno) { if (cardno.length == 19) return cardno; if (cardno.length != 16) throw new argumentexception("invalid card number.", "cardno"); return string.format( "{0}-{1}-{2}-{3}", cardno.substring(0, 4), cardno.substring(4, 4), cardno.substring(8, 4), cardno.substring(12, 4) ); }
this function convert card number 0001-1234-5678-9001
.
you can find card using code this:
var canonicalcardno = getcanonicalcardno(cardno); var card = cards.firstordefault(card => card.cardno == canonicalcardno);
the predicate used select card contains string comparision can executed on server side.
Comments
Post a Comment