在输入相同类型的字符串时出现错误
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)");
}
参数都是string
,并且在SQL Server nvarchar(13)
中
什么原因引起的?
答案 0 :(得分:1)
您的代码没有错。您需要仔细检查上下文是否与对象正确映射。
要比较不区分大小写的字符串,请使用此
var orderTransferFromDb = await context.OrderTransfer.FirstOrDefaultAsync(t => string.Equals(t.ToMemberMobilePhone, mobilePhone, StringComparison.OrdinalIgnoreCase));