Having problems with FirstofDefault returning wrong values. RRS feed

  • Question

  • User120938120 posted

    I have what looks to me to be a straitforward query:

    VirtualWallet WalletItem = context.VirtualWallets.FirstOrDefault(w => w.TokenID == theItem.TokenId);

    The table in the database has two rows.  the value of the TokenID field (which is a type of char(36)) in those two rows is 'blah' and 'blah2' respectively. 

    If the value of theItem.TokenId = 'Blah', the EF query above will return the row with the TokenID of 'blah' - padded with spaces.  This is not what I'm expecting.  I need it to be a case-sensitive search.

    But now if the value of theItem.TokenId is something far removed like 'Fred', then WalletItem will be null as expected.  

    This is with a SqlServer database on the back end.  

    Any ideas what I'm doing wrong?  Do I have something configured wrong somewhere else in the app?

    Tuesday, January 9, 2018 7:31 PM


All replies