Reputation: 33
Getting the error when asking for equal type of string in
var orderTransferFromDb = await context.OrderTransfer.FirstOrDefaultAsync(t =>
t.ToMemberMobilePhone.ToUpperInvariant().Equals(mobilePhone.ToUpperInvariant()));
public async Task<bool> UpdateOrderTransferToMemberId(string mobilePhone, string memberid)
{
if (mobilePhone != null)
{
using (var context = ContextManager.ClubContext())
{
var orderTransferFromDb = await context.OrderTransfer.FirstOrDefaultAsync(t => t.ToMemberMobilePhone.ToUpperInvariant().Equals(mobilePhone.ToUpperInvariant()));
if (orderTransferFromDb != null)
{
context.Attach(orderTransferFromDb);
orderTransferFromDb.ToMemberId = memberid;
await context.SaveChangesAsync();
}
return true;
}
}
throw new Exception("MobilePhone is null. (UpdteOrderTransferByEmail)");
}
The arguments are both string
, and in SQL Server nvarchar(13)
What can cause it?
Upvotes: 0
Views: 5098
Reputation: 5361
There's nothing wrong with your code. You need to double check your context whether is mapped correctly with your object.
To Compare string without case, use this
var orderTransferFromDb = await context.OrderTransfer.FirstOrDefaultAsync(t => string.Equals(t.ToMemberMobilePhone, mobilePhone, StringComparison.OrdinalIgnoreCase));
Upvotes: 1